这是我的代码:
def main(*args):
# The following code will look for arguments and record their start and
# end positions.
arg = False
arg_invalid = False
arg_start = -1
arg_end = -1
i = 1
print("main args = " + str(args))
...剥离了不相关的代码...
if __name__ == "__main__":
print("sys args = " + str(sys.argv))
print("tuple'd args = " + str(tuple(sys.argv)))
main(sys.argv)
和输出:
$ ./gmanager.py foo bar 128
sys args = ['./gmanager.py', 'foo', 'bar', '128']
tuple'd args = ('./gmanager.py', 'foo', 'bar', '128')
main args = (['./gmanager.py', 'foo', 'bar', '128'],)
如您所见, aftermain()
被调用,main()
将其参数放入一个元组中。我不希望这样,因为它会导致复杂的参数/字符串引用(arg[x][y][z]
)。
有没有办法在我的main()
函数中接受参数作为它们的先前状态,或者我可以从我的参数之外剥离元组?