After compiling a python program, how to enter arguments
After import sys
I use sys.argv
to enter input arguments.
But after compiling my program with pyinstaller, the exe program won't accept my data.
It will use the default I set for the program. How can I compile it and let the exe take my input?
I hope I don't need to write a gui for this. Sorry for the late reply. Here is the code:
import sched, time
import sys
s = sched.scheduler(time.time, time.sleep)
def do_something(sc,wait_time): //wait_time is an integer representing how many seconds to wait.
// Here will be the code for doing something every after "wait_time " seconds
sc.enter(wait_time,1,do_something,(sc,wait_time))
try:
wait_time = int(sys.argv[1])
except IndexError:
wait_time = 5
# s.enter(wait_time, 1, do_something, (s,))
s.enter(wait_time,5,do_something,(s,wait_time))
s.run()
If I run it with "python this_script.py" it will wait a few seconds for input to wait. But after I compiled it with pyinstaller, I double clicked the exe file. I have no place to enter a number that is wait_time.
source to share
If you click on the exe to open it:
Usually, when you double click the exe, there is only one argument <EXEfilename>
. Create a shortcut for this EXE. In the properties for this shortcut, you will see a property named Target
which will contain <EXEfilename>
change to <EXEfilename> <arg1> <arg2>
. When you use this shortcut to open the exe, it calls the target, which is that call <EXEfilename> <arg1> <arg2>
. Then you can access arg1
and arg2
withsys.argv
If you are using the command line:
Just call it C:\> <EXEfilename> <arg1> <arg2>
source to share