[Tutor] module re
Magnus Lyckå
magnus at thinkware.se
Sat May 1 12:31:55 EDT 2004
At 18:00 2004-05-01 +0200, Marina _ wrote:
>Hi,
>
>I need to write a program, that delete white spaces, comments, tabs etc. I
>used module re.compile(text, re.X). The problem is: the result is not a
>string, but an sre object, so I can't print it. Does anyone knows how can
>it be done? I have python2.3, Suse Linux 9.0
I'm not sure what you did, because re substitute functions
return strings. Deletion is the same as replacing with "",
right?
>>> import re
>>> x = re.sub("s", "z", "see his snowy sidewalk")
>>> type(x)
<type 'str'>
>>> print x
zee hiz znowy zidewalk
Anyway, you can certainly extract text from regular
expression objects, but I don't see why you want that.
--
Magnus Lycka (It's really Lyckå), magnus at thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language
More information about the Tutor
mailing list