Problem with re.match - Newbie needs some advice
John Machin
sjmachin at lexicon.net
Tue May 31 20:04:00 EDT 2005
rh0dium wrote:
> Hi all,
>
>I can't seem to get into the
> second re.match. Can someone point out my apparent error?
errorS:
1. Imprecision -- the problem is in the *third* re.match ...
2. ... which should be re.search
3. Using re at all when simple string methods would do -- see below
[snip]
> for line in self.cpudata:
> # Remove the newlines..
> ### line=line.strip()
tokens = line.split()
> ### if re.match(r"^processor\s+:", line):
if tokens[0] == "processor":
> cpucount += 1
> ### if re.match(r"^flags\s+:", line):
elif tokens[0] == "flags" and "ht" in tokens:
> ### flags=re.split(r":\s",line)
> #### print "Found flags", flags[1]
> ### if re.match(r"\bht\b",flags[1]):
> print "HT on"
> ht=1
More information about the Python-list
mailing list