0

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?

Mark
  • 513
  • 2
  • 8
  • 19

2 Answers2

2

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.

Community
  • 1
  • 1
Talmo Pereira
  • 192
  • 2
  • 7
1

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.

Levon
  • 138,105
  • 33
  • 200
  • 191
  • 1
    @downvoter .. why the downvote? OP seems satisfied with the answer. Downvotes w/o explanation help no one, OP, SO or me. – Levon Apr 15 '13 at 10:13