首页 > 解决方案 > 如何将 args 传递给 python shell

问题描述

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

$ python one two three

它会打开python shell,我可以获得以下信息:

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

标签: python

解决方案


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

$ python - one two three

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

这是一个链接,可以帮助您解决此类论点


推荐阅读