On 18/10/06, Chris Hengge <[EMAIL PROTECTED]> wrote:
> I remove those lines, but I was trying to use
> for line in contents:
> result = re.search("something", line)
> print result
>
> this printed out something like
>
> None
> None
> None
> hex memory address of goodness
> None
> None
If you don't need a regular expression, you are probably better off using 'in':
for line in contents:
if 'something' in line:
print line
Otherwise, re.search() and re.match() return either None or a match
object. So, you can do this:
for line in contents:
m = re.search('something', line)
if m:
print line[m.start():m.end()]
match objects become more powerful when you start using groups or
named groups in your regular expressions. See the documentation for
more :-)
--
John.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor