我想執行我的功能play()
使用帶有參數argparse模塊功能
import argparse
from num2words import num2words
def play():
parser = argparse.ArgumentParser()
parser.add_argument("--b", default=100,type=int,help="b")
args = parser.parse_args()
for file in reversed(range(file)):
print(num2words(iteration) + " there are")
print(num2words(iteration) + " there are")
我一直在python命令行運行:
>>> import myfile
>>> file.play()
但它一直使用default=100
,怎麼能例如,我指定了參數--b 10
?
看起來像你從交互式解釋(REPL),而不是shell(命令行) – wim
如何從外殼打來的? – Jshee
你可以覆蓋'sys.argv'的值,argparse會接受它。 –