无法访问Python 3.6中的命令行参数;python启动器的问题?
我最近终于将我的默认python从2.7移到了3.6 奇怪的是,我无法让sys.argv正常工作 短程序testargs.py:无法访问Python 3.6中的命令行参数;python启动器的问题?,python,windows,command-line-arguments,Python,Windows,Command Line Arguments,我最近终于将我的默认python从2.7移到了3.6 奇怪的是,我无法让sys.argv正常工作 短程序testargs.py: #!python3 import sys print("This is the name of the script: ", sys.argv[0]) print("Number of arguments: ", len(sys.argv)) print("The arguments are: " , str(sys.argv)) 当我使用参数(“abcdefg”)
#!python3
import sys
print("This is the name of the script: ", sys.argv[0])
print("Number of arguments: ", len(sys.argv))
print("The arguments are: " , str(sys.argv))
当我使用参数(“abcdefg”)运行它时,这些参数不会显示在sys.argv中:
C:\test>testargs.py abcdefg
This is the name of the script: C:\test\testargs.py
Number of arguments: 1
The arguments are: ['C:\\test\\testargs.py']
我完全被这搞糊涂了。有什么想法吗
我正在使用Python启动器;这是个问题吗
当我特别调用一个或另一个Python解释器时,它似乎没有问题:
C:\test>c:\Python27\python.exe testargs.py abcdefg
('This is the name of the script: ', 'testargs.py')
('Number of arguments: ', 2)
('The arguments are: ', "['testargs.py', 'abcdefg']")
C:\test>c:\Python36\python.exe testargs.py abcdefg
This is the name of the script: testargs.py
Number of arguments: 2
The arguments are: ['testargs.py', 'abcdefg']
这似乎是Python中长期存在的一个难以重现的错误:。bug报告包括一个注册表编辑,据报道它解决了这个问题,但我不喜欢处理它;所以我会一直接受它,直到我完全脱离Python 2