首页 > 解决方案 > 无法将参数传递给在 python shell 中运行的 python 脚本

问题描述

我正在使用 Windows 10,我编写了一个 python 脚本来打开一个外部 .exe 程序。Python 版本是 Python 3.6。
subprosee.Popen(command, shell = True)用来运行命令。(如果我没有包含 shell=True 参数,它将无法正常工作)
有一句话print(sys.argv)。当我>python program.py arg1 arg2在 Windows 命令提示符下运行命令时,将启动一个 python shell 并显示两次。在命令提示符中显示:
['program.py' 'arg1' 'arg2']
但是,在 python shell 中显示:
['program.py']
这意味着参数没有正确传递到 python 脚本中。我应该如何解决这个问题?我在网上搜索了一些提示,有人提到了关联配置。我做了以下事情:
assoc .py=Python.File ftype Python.File="C:\Anaconda3\python.exe" "%1" %*
但奇怪的是,虽然我可以Python.File="C:\Anaconda3\python.exe" "%1" %*通过找到,但它会在我输入时ftype | findstr -i python显示。File type 'Python.File' not found or no open command associated with it.ftype Python.File
在此处输入图像描述 我还手动配置了注册信息。 r 那么我应该怎么做才能解决这个问题呢?你的帮助对我来说非常重要。

标签: pythonpython-3.x

解决方案


推荐阅读