Python Fire用于自動(dòng)生成命令行界面的內(nèi)容庫(kù)
Python Fire 是 Google 開源的一個(gè)可從任何 Python 代碼自動(dòng)生成命令行接口(CLI)的庫(kù)。
-
Python Fire 是一種在 Python 中創(chuàng)建 CLI 的簡(jiǎn)單方法。
-
Python Fire 是開發(fā)和調(diào)試 Python 代碼的有用工具。
-
Python Fire 幫助探索現(xiàn)有代碼或?qū)⑵渌说拇a轉(zhuǎn)換為CLI。
-
Python Fire 使 Bash 和 Python 之間的轉(zhuǎn)換更為容易。
-
Python Fire 通過(guò)使用你需要導(dǎo)入和創(chuàng)建的模塊和變量來(lái)設(shè)置 REPL,使得使用 Python REPL 更容易。
簡(jiǎn)易示例:
import fire class Calculator(object): """A simple calculator class.""" def double(self, number): return 2 * number if __name__ == '__main__': fire.Fire(Calculator)
然后,你可以運(yùn)行:
python calculator.py double 10 # 20 python calculator.py double --number=15 # 30
評(píng)論
圖片
表情
