[Tutor] regexing and timing, seperatly
Sean 'Shaleh' Perry
shalehperry@attbi.com
Mon, 7 Oct 2002 22:24:31 -0700
On Monday 07 October 2002 22:18, Galen O'Neil wrote:
> 1. I can't seem to find a simple tutorial or example on timing. I wan=
t
> an infinite loop but I don't want it to eat all my cpu time. I've
> looked at a few programs that use tkinter and root.mainloop() but I
> can't imagine there aren't some other ways that don't involve tkinter.
> So if anybody knows where I can find a decent tutorial or has some
> sample code, that would be great.
>
this is not clear. Are you trying to have a timer so that your program d=
oes=20
something on certain intervals?
> 2. I'm taking data from a telnet session (using telnetlib) but I can't
> seem to do regexs on it. Here's an example:
>
> this result from this code:
>
> print "***searching data, data at this moment contains***"
> print data
> import re
> m =3D re.match("Player", data)
> if m:
> print 'Match found: ', m.group()
> else:
> print 'No match'
>
you used re.match() which searches for the regex at the beginning of the=20
string. It is basically for when the string is expected to exactly match=
the=20
regex. What you want is re.search, it is used the same way just a differ=
ent=20
function name.
words =3D string.split(sentence)
for word in words:
if re.match(r"\w+"):
print "I am a valid python variable name"
is the type of logic where match makes sense. Basically think of match a=
s the=20
equivalent of always adding "^" to the front of your regex.