Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过-我";到读取其他参数的python脚本_Python_Command Line_Arguments_Parameter Passing_Command Line Arguments - Fatal编程技术网

如何通过-我";到读取其他参数的python脚本

如何通过-我";到读取其他参数的python脚本,python,command-line,arguments,parameter-passing,command-line-arguments,Python,Command Line,Arguments,Parameter Passing,Command Line Arguments,不需要来自命令行的额外参数的普通python脚本可以在完成时通过传递-i进入python来执行。我想知道当我的脚本使用sys.argv读取多个其他参数时,如果我也想在完成时输入python,该怎么办?因为此时它返回读取的参数的错误。谢谢 这很好用: python -i myscript.py arg1 arg2 arg3 例如: nosklo@stackoverflow:~$ touch foobar.py # create empty file nosklo@stackoverflow:~$

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

这很好用:

python -i myscript.py arg1 arg2 arg3
例如:

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

python -i myscript.py arg1 arg2 arg3
例如:

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