sys.stdin and re.search

Erik Max Francis max at alcyone.com
Mon Jan 20 08:26:59 CET 2003


Jimmie Fulton wrote:

> I'm unable to get any matches with re in a loop when the file I'm
> looping
> over is stdin.  When I use open(), it works fine.  Any hints?

No obvious differences are jumping out at me.  Maybe if you showed us
the file you're using and how you're invoking the script in either way?

By the way, a more idiomatic way to iterate over every line in a file
is:

	while 1:
	    line = F.readline()
	    if not line:
	        break
	    ...

In modern versions, you can just iterate over the file object itself:

	for line in F:
	    ...

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Does the true light / Of love come in flashes
\__/ Sandra St. Victor
    CatCam / http://www.catcam.com/
 What do your pets do all day while you're at work?  Find out.




More information about the Python-list mailing list