what does "lost sys.stdin" error mean?

Tim Harig usernet at ilthio.net
Thu Jun 11 19:01:16 EDT 2009


On 2009-06-11, lynvie <lyndiechiou at gmail.com> wrote:
> I have a very simple program from the first chapter of a book on
> python 3 (I'm a novice). I called the program tmp.py and the data
> input file is sum.dat (just a list of numbers, 1 per line). When I
> type into my command shell "tmp.py < sum.dat" I get an error from

What OS are you using?  I know that pipes cause issues when working with
interpreters on Windows.  You must call the python interpreter directly or
it will not be able to handle the pipe directly.  I don't remember exacly
how the issue manifests but I remember it has bitten me before on Win32.  I
don't currenlty have a Windows machine to test on.

> "line=input()" -- that's line 7 from the code below. The exact error
> message is:
> RuntimeError: input(): lost sys.stdin.

I am working on Linux and I have been unable to produce your error.  My
Python version identifies itself as:

>>> import sys
>>> sys.version
'3.0.1 (r301:69556, Mar 17 2009, 11:42:03) \n[GCC 4.1.2]'

This is what I have done using your same tmp.py file as pasted from
a shell session:

17:52,505$ count=0

17:53,506$ while [ $count -lt 20 ]; do
	echo $RANDOM >> sum.dat;
	newcount=`echo "$count + 1" | bc`;
	count=$newcount;
done

17:53,507$ python3.0 tmp.py < sum.dat
Type integers, each followed by Enter; or ^D or ^Z to finish
number = 22657
count = 1 total = 22657 mean = 22657.0
number = 12223
count = 2 total = 34880 mean = 17440.0
number = 10250
count = 3 total = 45130 mean = 15043.3333333
number = 20919
count = 4 total = 66049 mean = 16512.25
number = 20995
count = 5 total = 87044 mean = 17408.8
number = 28988
count = 6 total = 116032 mean = 19338.6666667
number = 13015
count = 7 total = 129047 mean = 18435.2857143
number = 25701
count = 8 total = 154748 mean = 19343.5
number = 6566
count = 9 total = 161314 mean = 17923.7777778
number = 19396
count = 10 total = 180710 mean = 18071.0
number = 16771
count = 11 total = 197481 mean = 17952.8181818
number = 2039
count = 12 total = 199520 mean = 16626.6666667
number = 655
count = 13 total = 200175 mean = 15398.0769231
number = 27417
count = 14 total = 227592 mean = 16256.5714286
number = 5000
count = 15 total = 232592 mean = 15506.1333333
number = 12015
count = 16 total = 244607 mean = 15287.9375
number = 8746
count = 17 total = 253353 mean = 14903.1176471
number = 29487
count = 18 total = 282840 mean = 15713.3333333
number = 3194
count = 19 total = 286034 mean = 15054.4210526
number = 8225
count = 20 total = 294259 mean = 14712.95

As you can see, it seems to be working as prescribed.



More information about the Python-list mailing list