When I created a Windows executable file using Python, I wanted to process it using command line arguments, but I record the trap that occurred at that time as a reminder.
hello.py
import sys
str1 = sys.argv[1]
print(str1)
python test.py helloworld
>>> helloworld
pyinstaller hello.py --onefile
IndexError: list index out of range
The cause was that the list could not be created because it does not use the command line.
hello.py
str1 = input("please put something")
print(str1)
>>>please put something
helloworld
As a result of trial and error, I could not get the command line arguments using sys, so I decided to use the Input function and it worked. If anyone knows how to use command line arguments in a Windows executable, I'd love to hear from you.
Recommended Posts