I getting an error when I try to run this function here:

def get_char_out(prompt=None):
   while True:  
     try:
        return str(raw_input(prompt + ' '))
        break
     except ValueError:
       print '\nInvaild input'

print get_char_out('String, please')

I keep getting this error here:

String, please Traceback (most recent call last):
  File "main.py", line 11, in 
    get_char_out('String, please')
  File "main.py", line 6, in get_char_out
    return str(raw_input(prompt + ' '))
EOFError: EOF when reading a line

get_char_out returns the prompt, but then I run into the EOF error. I understand that EOF has something to do with ending input, but this has me a bit stumped.

Thanks in advance!

Recommended Answers

All 4 Replies

Apparently, the stream sys.stdin was closed when your program attempted to read a line. In which context did you run the program ? Which OS first ? was it in a python IDE ? was it in a terminal ? Did you type a CTRL D in a terminal while running the program ? Was the program called from another program ?

I think i've just realize my problem. I was having problems running the code on my laptop, so I decided to test it online to see if the code was glitchly in some way, or if my python enveronment is set up wrong. Because I'm a derp, I forgot that the input file the website used (input.txt) had to be treated like a file, not a makeshift commard line. Silly me. Anyway, the code still comes up with an indention error on my laptop, but the commard box only shows for a few seconds before going off again. Any quick fix for this?

Using Notepad++, and Python 2.7.4

I don't know how you launch the program from notepad++, but if you can invoke python with option -i, it should prevent the cmd from closing.

BTW, the indent error was due to a silly mix of tabs and 4-spaces. Another bad programming habit consumed and no more!! I'm now just running code dicrectly off cmd, so that's fixed as well. All is well!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.