如何将“-i”传递给读取其他参数的 python 脚本

how to pass "-i" to a python script that reads in other arguments

一个普通的python脚本不需要命令行的额外参数,可以通过传递-i来执行,完成后输入python。我想知道当我的脚本使用 sys.argv 读取多个其他参数时如果我想在完成时也输入 python 该怎么办?因为目前正在读取参数 returns 错误。谢谢!

这很好用:

python -i myscript.py arg1 arg2 arg3

示例:

nosklo@Whosebug:~$ touch foobar.py # create empty file
nosklo@Whosebug:~$ python -i foobar.py arg1 arg2
>>> import sys
>>> sys.argv
['foobar.py', 'arg1', 'arg2']