Problems reading fra sys.stdin and later on duing raw_input

Peter Kristensen pkr at netnord.dk
Fri Mar 17 13:59:13 CET 2000


Hey

I want to read a file from sys.stdin and then later on do a
raw_input. But I get an error because sys.stdin is closed after the
file is read.

Here is an example that illustrates the problem.

/tmp/x.py:
        #!/usr/bin/env python

        import sys

        lines = sys.stdin.readlines()
        for line in lines:
            print line

        a = raw_input('Prompt: ')
        print a


pkr at perm:~> echo -n "test" | /tmp/x.py 
test
Prompt: Traceback (innermost last):
  File "/tmp/x.py", line 9, in ?
    a = raw_input('Prompt: ')
EOFError: EOF when reading a line

Is there *any* way I can solve this problem?

Btw, I use python-1.5.2 on Linux 2 and Solaris 7


Regards,
Peter Kristensen



More information about the Python-list mailing list