Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting object to string

Status
Not open for further replies.

tompol

Programmer
Jun 19, 2003
1
NZ
hi there,
i have an object reference "_sre.SRE_Pattern object at 0x01180C40"
how do i convert this into the string representative?

i am creating a simple dom oriented code project that takes in a .txt file and then prints it out in xml format.

Code:
import re
from xml.dom.minidom import *

def main():

    f = open('1.txt', 'r')
    text = f.readlines()
    f.close()
    
    doc = Document()
    co = doc.createElement("2003 Course Outline")
    doc.appendChild(co)

    keyRE = re.compile('(^[0-9])\t(\b[A-Z])\n')
    for line in text:
        firstLine = repr(keyRE) #????????
        co2 = doc.createElement(firstLine)
        co.appendChild(co2)

        print doc.toprettyxml(indent="  ")
if __name__ == '__main__':
    main()

the txt file im using only has this in it
"1 COURSE STAFF MEMBERS"

The print out of it returns this
>>> <?xml version=&quot;1.0&quot; ?>
<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 &quot;<COURSE STAFF MEMBERS>&quot; and not
<_sre.SRE_Pattern object at 0x01180C40>

how do i do this???

thankyou
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top