Я недавно наконец-то переместил свой Python по умолчанию с 3,6 на 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"), эти аргументы не отображаются в 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']