sys.stdin and re.search
Jimmie Fulton
jimmie-dated-1043474834.7879b0 at illumid.com
Mon Jan 20 01:24:24 EST 2003
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?
Sample Non-working code...
<code>
import re,sys
pattern = re.compile(r"(\b[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\b)")
line = sys.stdin.readline()
while line:
match = pattern.search(line)
if match:
print match.groups()
line = sys.stdin.readline()
</code>
Sample Working code...
<code>
import re,sys
pattern = re.compile(r"(\b[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\b)")
file = open('myfile','r')
line = file.readline()
while line:
match = pattern.search(line)
if match:
print match.groups()
line = file.readline()
</code>
Thanks for any advice you can give,
Jimmie Fulton
More information about the Python-list
mailing list