Re: Silly question re: 'for i in sys.stdin'?

2005-04-04 Thread Jeff Epler
On Sun, Apr 03, 2005 at 09:49:42PM -0600, Steven Bethard wrote: Slick. Thanks! does isatty() actually work on windows? I'm a tiny bit surprised! Jeff pgp2TeZpqhdyV.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Silly question re: 'for i in sys.stdin'?

2005-04-04 Thread Steven Bethard
Jeff Epler wrote: On Sun, Apr 03, 2005 at 09:49:42PM -0600, Steven Bethard wrote: Slick. Thanks! does isatty() actually work on windows? I'm a tiny bit surprised! Hmm... I was just talking about using iter(f.readline, ''), but it does appear that isatty returns True for sys.stdin in the

Re: Silly question re: 'for i in sys.stdin'?

2005-04-04 Thread Tom Eastman
Jeff Epler wrote: The iterator for files is a little bit like this generator function: SNIP Cool thanks for that, it looks like iter(f.readline, '') is the best solution for the job. Tom -- http://mail.python.org/mailman/listinfo/python-list

Silly question re: 'for i in sys.stdin'?

2005-04-03 Thread Tom Eastman
I'm not new to Python, but I didn't realise that sys.stdin could be called as an iterator, very cool! However, when I use the following idiom: for line in sys.stdin: doSomethingWith(line) and then type stuff into the program interactively, nothing actually happens until I hit CTRL-D.

Re: Silly question re: 'for i in sys.stdin'?

2005-04-03 Thread David Trudgett
I'm not a Python expert by any means, but you're describing the classic symptoms of buffering. There is a '-u' command line switch for python to turn off buffering but that does not affect file iterators. See http://www.hmug.org/man/1/python.html for instance. Tom Eastman [EMAIL PROTECTED]

Re: Silly question re: 'for i in sys.stdin'?

2005-04-03 Thread Jeff Epler
The iterator for files is a little bit like this generator function: def lines(f): while 1: chunk = f.readlines(sizehint) for line in chunk: yield line Inside file.readlines, the read from the tty will block until sizehint bytes have been read or EOF is seen.

Re: Silly question re: 'for i in sys.stdin'?

2005-04-03 Thread Steven Bethard
Jeff Epler wrote: The iterator for files is a little bit like this generator function: def lines(f): while 1: chunk = f.readlines(sizehint) for line in chunk: yield line Inside file.readlines, the read from the tty will block until sizehint bytes have been read