|
|
金子邦彦研究室: データベース、人工知能(AI)、データサイエンスの融合により不可能を可能にする |
前準備として,Python 処理系のインストールが終了していること. Windows で Anaconda を使用しているものとして説明しますが,他の Python 処理系でも同様の手順です.
※ Linux の場合には,端末を開く(pyenvを使っているときは pip の実行に管理者権限を必要としない)
pip install --ignore-installed --upgrade fire
※ 「Proceed ([y]/n)?」と表示されたら, y + Enter で続行する.「反応が遅いなあ」と思ったら、Enter キーを押してみる.
エラーメッセージが出ていないことを確認する
conda list fire
fire の使用法については: https://github.com/google/python-fire/blob/master/docs/using-cli.md
次のファイルを作り, hoge.pyのようなファイル名で保存
import fire
def foo(a):
return(a * 1.08)
if __name__ == '__main__':
fire.Fire(foo)
端末 (Windows のコマンドプロンプトなど)を開き,次を実行
python hoge.py 100 python hoge.py 150 python hoge.py 400
import fire
class C(object):
def __init__(self, qty, weight, name):
self.qty = qty
self.weight = weight
self.name = name
def total(self):
return self.qty * self.weight
if __name__ == '__main__':
fire.Fire(C)
端末 (Windows のコマンドプロンプトなど)を開き,次を実行
python hoge.py --qty 5 --weight 170.51 --name 'apple' qty python hoge.py --qty 5 --weight 170.51 --name 'apple' weight python hoge.py --qty 5 --weight 170.51 --name 'apple' name python hoge.py --qty 5 --weight 170.51 --name 'apple' total