python CMD命令行傳參實現(xiàn)方法(argparse、click、fire)
1、argparse
設置傳入和默認參數(shù),也可以通過–help參考具體設置參數(shù)

bool值

參考:
https://docs.python.org/zh-cn/3/howto/argparse.html
https://www.bilibili.com/video/BV1nb41157Zc
expected one argumrnt 報錯,傳入坐標類型字符串
1) 添加 nargs=‘*’,可以支持傳多個值,傳參用空格,這樣打印結果是一個列表,列表再join成坐標字符串
python test.py -cb_ticks 1 2 5
## test.py
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(' cb_ticks', nargs='*')
args = vars(parser.parse_args())
print(args.cb_ticks)2)需要多加個引號,兩個引號才行

2、click
import click
@click.command()
@click.argument('input_text')
def main(input_text):
click.echo(input_text.upper())
if __name__ == '__main__':
main()3、fire
import fire
def infer(input_text):
"""
A simple function to process input text.
"""
processed_text = input_text.upper()
return processed_text
if __name__ == '__main__':
fire.Fire(infer)
到此這篇關于python CMD命令行傳參實現(xiàn):argparse、click、fire的文章就介紹到這了,更多相關python CMD命令行傳參內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
python實現(xiàn)畫出e指數(shù)函數(shù)的圖像
今天小編就為大家分享一篇python實現(xiàn)畫出e指數(shù)函數(shù)的圖像,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
python圖形開發(fā)GUI庫wxpython使用方法詳解
這篇文章主要介紹了python GUI庫wxpython使用方法詳解,需要的朋友可以參考下2020-02-02

