converting objects to string

Duncan Booth duncan at
Mon Jun 30 12:23:38 CEST 2003

tompol at (huntermorgan) wrote in 
news:78cae312.0306300054.5e31084e at

> the txt file only has this in it "1     COURSE STAFF MEMBERS"
> The print out of it returns this
>>>> <?xml version="1.0" ?>
><2003 Course Outline>
>  <<_sre.SRE_Pattern object at 0x01180C40>/>
></2003 Course Outline>
> as you can see 'repr(keyRE)' doesnt work
> i would like the string "<COURSE STAFF MEMBERS>" and not 
><_sre.SRE_Pattern object at 0x01180C40>/
> how do i do this???

You would have to match the regular expression against the line you had 
read in and you could then extract the fields from the match object.

However, a better way here is simply not to use regular expressions at all. 
Just use the split method on the input string:

    for line in text:
        number, name = line.split('\t', 1)
        print number, name

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list