Advertise here: Contact FM.
from optparse import OptionParser
op = OptionParser()
op.add_option('-r', '--root', default='metafilter')
op.add_option('--cdata', default=False, action='store_true')
op.add_option('--escape', dest='munge', default=False, action='store_true')
opts, args = op.parse_args()
if opts.munge and opts.cdata:
op.error('CDATA and HTML munging modes are mutually exclusive!')$ ./test.py -h Usage: test.py [options] [infile [outfile]] If infile is not specified, "my-mefi-comments.txt" will be used. If outfile is not specified, "my-mefi-comments.xml" will be used. Options: --version show program's version number and exit -h, --help show this help message and exit -r NAME, --root=NAME specify root XML node (default: metafilter) -c, --cdata protect HTML using CDATA -e, --escape protect html by escaping
#!/usr/local/bin/python
import taking_ball_and_going_home
import have_knife_leaving_handdos2unix to get rid of the carriage returns (^M) and change the shebang to #!/usr/bin/python firstThe request has exceeded the allowable time limit Tag: cfoutputThe information above can help us diagnose the problem, thanks.
The error occurred on line 48.
- Current Page: document.write(document.location);
- Referring Page: http://www.metafilter.com/contribute/my-mefi-export.mefi
- Date and Time: Wed Apr 15 14:20:04 PDT 2009
- Your Browser: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8 GTB5 (.NET CLR 3.5.30729)
- Your Location: xxx.104.102.4
out = open("outfile.xml", "w")
print >>out, "<document>"
for record in something:
elem = ET.Element("record")
# populate elem with whatever data you have
ET.SubElement(elem, "field").text = u"value"
ET.SubElement(elem, "otherfield", key="value")
# write it to disk
elem.tail = "\n"
print >>out, ET.tostring(elem)
print >>out, "</document>
out.close()
This only requires you to hold one comment (or whatever record data you have), and since the ET structures only holds references to the data you add to the tree, the memory overhead is pretty marginal (25-50 bytes per node, or so).
Also, Python makes me very happy. Thank you, Kadin2048, for coming back in time 39 years to tell us this.
posted by koeselitz at 9:55 PM on April 14