【发布时间】:2020-05-30 02:52:19
【问题描述】:
您好,我正在尝试编写一个函数,该函数将采用不同的参数和 将在另一个脚本的另一个函数中使用。我的想法是能够直接从终端精确参数,脚本将在某种程度上使用精确参数执行函数并应用正确的行。
所以我像这样运行我的脚本并将 f 这是我的参数但我没有任何答案,放在完整的脚本下方。
C:\Users\Etu\ocuments>python test2.py f
第一个脚本
import sys
first_arg = sys.argv[1]
texte = "je MaNgE"
def get_command(texte, first_arg):
if first_arg =="f":
texte = texte.lower()
return texte
elif first_arg=="t":
return texte.split()
elif first_arg =="r":
return texte
else:
raise Exception("Wrongfile feature type entered. Possible values: 't','f', 'r")
第二个脚本
from test import *
texte = "je MaNgE"
def choose (texte):
texte=get_command(texte, first_arg)
print(texte)
想法是直接从shell修改参数,而不是一直进入脚本内部。
【问题讨论】:
-
查看
sys.argv或单击哪个为您提供处理命令行参数的工具。 -
我试了,但是不行,能不能帮我调试一下代码
标签: python python-3.x dataframe arguments