I'm trying to keep my python program running but it closes right away. I have tried raw_input()
but I get this error: EOFError: EOF when reading a line
I put raw_input()
at the end. What should I use to have it running?
What you want to do is compile an EXE using py2exe specifying that it's a console app . This is why you're getting an EOF error, there's no stdin for raw_input()
to read from.
Create a setup.py like this:
from distutils.core import setup
import py2exe
setup(console=['your_script.py'])
Then you can just compile it by running this in a console window:
python setup.py py2exe
This will produce your_script.exe in that directory which should stay open as a console window if you have a raw_input()
at the end of your script.
Make sure setup.py and your_script.py are in the same directory and that you have py2exe installed.
For reference, you can get py2exe online .
Incidentally, this also allows you to use commandline arguments in your py2exe programs.
I don't have access to Python right now, but something like
from time import time, sleep
while True:
#do other stuff
sleep(5)
should be close. This would sleep for 5 seconds each time through the loop, see the docs for time.sleep() . Adjust the time to fit your needs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.