Re: Something that Perl can do that Python can't?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Something that Perl can do that Python can't?

From: George Sakkis <gsakkis@rutgers.edu>
Date: Sat Jul 23 2005 - 01:31:49 CEST

"Dr. Who" <google@spiceaid.com> wrote in message
news:1122066437.870669.58990@z14g2000cwz.googlegroups.com...
> Well, I finally managed to solve it myself by looking at some code.
> The solution in Python is a little non-intuitive but this is how to get
> it:
>
> while 1:
> line = stdout.readline()
> if not line:
> break
> print 'LINE:', line,
>
> If anyone can do it the more Pythonic way with some sort of iteration
> over stdout, please let me know.
>
> Jeff

You can use the sentinel form of iter():

for line in iter(stdout.readline, ''):
    print 'LINE:', line,

George
Received on Thu Sep 29 17:06:56 2005