read from standard input

Steve Holden sholden at holdenweb.com
Sun Aug 11 17:36:03 EDT 2002


"Oren Tirosh" <oren-py-l at hishome.net> wrote in message
news:mailman.1028916198.32031.python-list at python.org...
> On Fri, Aug 09, 2002 at 04:04:31PM +0200, Jaroslav Jákl wrote:
> > Hi all,
> > I want to read from stdin. I have the following script:
> >
> > import sys
> > for line in sys.stdin.readlines():
> >     print line
> >
> > and if i execute it like script.py < file, i get IOError: [Errno 9] Bad
file
> > descriptor.
>
> I cannot reproduce this. Here it works just fine. Which Python version
> are you using?
>
> BTW, if you are using Python 2.2 or higher you can use
>
>   for line in sys.stdin:
>
> and avoid reading the entire file into memory first.
>

NEITHER of you have said which platform you are using! This does smell like
a platform dependency.

For what it's worth, it works as an interactively-entered script under
Python 2.2.1-1 on Cygwin/Win2000, as well as under the standard Windows 2000
Python 2.2.

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list