[Tutor] advice on idiomatic python and re module question

Andrew Fant fant at pobox.com
Mon May 17 14:34:43 EDT 2004


Afternoon all,
   After intending to get serious about learning python for a couple years 
now, I have finally bit the bullet and started to use python for odd jobs 
around the office.  I have run into a couple issues that I could use some 
help with, though.

First, I cannot seem to compile and use more than one regexp in a program:

if I use:

pattern1=re.compile('^#')
pattern2=re.compile('eth0')

to define the patterns, I can use:

if pattern1.match(line):

to check for a comment line succesfully,but

if pattern2.match(line):

always fails, even when a file containing that string is read in.  Grep has 
no trouble finding the string, and I have single stepped through the code 
with a debugger and I see the line fail to match.   Doe anyone have any 
suggestions on what I am doing wrong?

Also, I have written a short (143 line) program to read the output of a 
program called wulflogger ( 
http://www.phy.duke.edu/~rgb/Beowulf/wulflogger.php for the curious) and 
break the output out by hostname in a format that orcalator can handle and 
also generate an average of all the data that can be read by orcalator.  To 
my eyes, it is clearly the product of someone who still thinks in F77.  I 
won't post it here unless there is heavy demand, but I was wondering if 
there is someone who would be willing to read through it and give me some 
feedback about how to make the code more idiomatic and generic.

Thanks in advance,
		Andy




More information about the Tutor mailing list