如何将args传递给python shell

时间:2020-09-10 01:56:25

标签: python

我想在python shell中玩弄sys.argv中的项目。有没有办法传递任意参数,例如:

$ python one two three

这将打开python shell,我可以得到以下信息:

>>> import sys
>>> sys.argv
# ['python', 'one', 'two', three'],  or ['one', 'two', 'three']

1 个答案:

答案 0 :(得分:3)

您可以在连字符后传递这些参数,例如:

$ python - one two three

在这种情况下,sys.argv将产生['-', 'one', 'two', 'three']

Here is a link that will help you with such arguments