converting objects to string
huntermorgan
tompol at hotmail.com
Mon Jun 30 04:54:47 EDT 2003
hi there,
i have an object reference "_sre.SRE_Pattern object at 0x01180C40"
how to 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.
<start_of_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()
<end_of_code>
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???
thankyou
More information about the Python-list
mailing list