In Python2.7 on Windows environment For example, if you have the following test.py
import sys
print(len(sys.argv))
Even if I execute it from the command prompt with arguments, sys.argv is always 1.
> test.py a b c
1 // <= NG:Should be 4
There is no problem if you execute it from the python command.
> python test.py a b c
4 // <= OK
It was listed as an issue at https://bugs.python.org/issue7936. In conclusion, mess with the registry.
Launch regedit and go to HKEY_CURRENT_USER \ Software \ Classes \ Applications \ python.exe \ shell \ open \ command
If this value is " C: \ Python27 \ python.exe ""% 1 "
, modify it to " C: \ Python27 \ python.exe ""% 1 "% *
.
This should allow sys.argv to be passed correctly.
> test.py a b c
4 // OK
Even so, it was a bug reported 6 years ago, so I really wanted it to be fixed.
Recommended Posts