前言
Python之所以強大,是因爲它擁有各種各樣的庫,今天爲大家介紹一款酷酷的庫,Python Fire 是 Google 開源的一個可從任何 Python 代碼自動生成命令行接口(CLI)的庫。
- Python Fire 是一種在 Python 中創建 CLI 的簡單方法。
- Python Fire 是開發和調試 Python 代碼的有用工具。
- Python Fire 幫助探索現有代碼或將其他人的代碼轉換爲CLI。
- Python Fire 使 Bash 和 Python 之間的轉換更爲容易。
- Python Fire 通過使用你需要導入和創建的模塊和變量來設置 REPL,使得使用 Python REPL 更容易。
簡易示例:
import fire
class Calculator(object):
"""A simple calculator class."""
def double(self, number):
return 2 * number
if __name__ == '__main__':
fire.Fire(Calculator)
然後,你可以運行:
python calculator.py double 10 # 20
python calculator.py double --number=15 # 30```
>小編推薦一個學python的學習qun 740322234