gpt4 book ai didi

Python 不会读取 sys.argv

转载 作者:太空狗 更新时间:2023-10-29 21:16:14 25 4
gpt4 key购买 nike

    import sys

print sys.argv[1]

你好,

这可能看起来很基础,但我无法让 Python 从命令行读取任何内容。这就是上面的代码,我输入的是:

    myfile.py helloworld

我得到的是:

    IndexError: list index out of range

它似乎对我有用一次,但不会再起作用了,我已经尝试卸载并重新安装 Python,但它仍然不起作用。

所以我的问题是,我做错了什么吗?还是我刚刚破坏了 Python?

感谢您的帮助

使用:Windows 7的Python 2.7.2

最佳答案

启动注册表编辑器 (regedit)。将 HKEY_CLASSES_ROOT\Applications\python26.exe\shell\open\command 键设置为:"C:\Python26\python26.exe""%1"%*

此解决方案的来源:http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows/

关于Python 不会读取 sys.argv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7969168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com