[Raspberry Pi] python-fmrest で FileMaker Data API を使う2

python-fmrest で FileMaker Data API を使う方法について書いた。

さらに、コマンドライン引数を渡して Python スクリプトを実行してみた。abc というコマンドライン引数を Python スクリプト内で使用してみよう。

なおこれは python-fmrest に限らず、Python スクリプト一般に使う手法だ。

環境:
・Raspberry Pi 3 Model B(Buster Desktop)
・VMware vSphere Hypervisor 7.0U3g(英語環境)、VMware Photon OS 5.0 の Docker で FileMaker Server 19.6.3.302

(1)以下のような test.py という Python スクリプトを作成する。

import fmrest
import sys

args = sys.argv

fms = fmrest.Server(
  '{https://{FMS の IP アドレス}',
  user='{データベースのユーザー名}',
  password='{データベースのパスワード}',
  database='{データベース名}',
  layout='{レイアウト名}',
  verify_ssl=False,
  api_version='v1'
)
fms.login()
hoge = fms.create_record({'field1': args[1]})
fms.logout()

「field1」フィールドにコマンドライン引数の abc を入力してレコードを新規作成するようにしている。

(2)以下のコマンドを実行する。

$ python3 test.py abc

参考:
Pythonでコマンド引数を渡して受け取る方法!(sys.argv) | コードライク
https://codelikes.com/python-command-args-sys/

Pythonのコマンドライン引数がわかる!渡し方・取得方法を分かりやすく解説 - TechTeacher Blog
https://www.tech-teacher.jp/blog/python-commandline/

Pythonでコマンドライン引数を受け取る - Qiita
https://qiita.com/taashi/items/07bf75201a074e208ae5


この記事が気に入ったらサポートをしてみませんか?