python - 无法将参数传递给在 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
我还手动配置了注册信息。
那么我应该怎么做才能解决这个问题呢?你的帮助对我来说非常重要。
解决方案
推荐阅读
- python - python中的SQL输出-如何将数据框中的所有元组转换为字符串
- c++ - 在 C++ 中重放函数调用
- python-3.x - backtrader 打印数据提要 vaues 不打印小时和分钟,默认为
- git - 上传使用 git clone 复制的项目的一部分
- arrays - 将一组输入映射到另一个数组
- python - 使用分隔符python在列表python中切片字符串
- ios - 在旧版 iOS 模拟器上运行时,出现错误“无法启动 launchd_sim:无法绑定到会话,launchd_sim 可能已崩溃或退出响应”
- reactjs - 在没有 forwardRef 的情况下处理函数组件中的 ref
- qt - 将图像从文件夹加载到精确坐标
- python - 多单选按钮选择