ElementTree : parse string input
Hi, recently having discovered ElementTree I'm stumped by a very simple problem, which I can't find the answer to. I have some XML in a string object. Now the parse() method of ElementTree takes a filename or file-like object. So I tried creating a StringIO object from the original string and then giving that to parse(). But that does not seem to work. Any pointers to getting ElementTree to parse from a string would be appreciated (of course I could dump it to a temp file, but that doesn't seem elegent) Thanks, Rajarshi -- http://mail.python.org/mailman/listinfo/python-list
Re: iterate over a series of nodes in an XML file
Stefan Behnel wrote: > [EMAIL PROTECTED] wrote: > > I have an XML file which contains entries of the form: > > > > > > 1 > > 2 > > > > 1 > > Thanks to everybody for the pointers. ElementTree is what I ended up using and my looks like this (based on the ElementTree tutorial code): def extractIds(filename): f = open(filename,'r') context = ET.iterparse(f, events=('start','end')) context = iter(context) even, root = context.next() for event, elem in context: if event == 'end' and elem.tag == 'Id': yield elem.text root.clear() As a result I can do: for id in extractIds(someFileName): do something -- http://mail.python.org/mailman/listinfo/python-list
iterate over a series of nodes in an XML file
Hi, I have an XML file which contains entries of the form: 1 2 1 Currently, I have written a SAX based handler that will read in all the entries and return a list of the contents of these entries. However this is not scalable and for my purposes it would be better if I could iterate over the list of nodes. Some thing like: for myid in getMyIDList(document): print myid I realize that I can do this with generators, but I can't see how I can incorporate generators into my handler class (which is a subclass of xml.sax.ContentHandler). Any pointers would be appreciated Thanks, Rajarshi -- http://mail.python.org/mailman/listinfo/python-list
packaging a python project and associated graphics files
Hi, I've been trying to package a python project and I'm a little confused about how I distribute some PNG's that the program uses as icons. Using distutils I can set the data_files argument of setup() and get my data files located in, say, /usr/local/mydata. However when I write my code, it would seem that I have to hardcode the above path. But this would mean that while working on the code I would need to have it 'installed' on my system (or else actually make the above directory). This seems a little unwieldy. How do people handle this situation? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
accesing pages (or ranges of pages) via Reportlab
Hi, I've been using pdflatex to dump ranges of pages from a PDF file via Python. However, I was looking at the Reportlab toolkit and was wondering if this operation would be possible using this toolkit as well. Admittedly, I have'nt read the documentation in detail, but I was wondering if anybody could provide any pointers to extracting pages from a PDF via Python without using pdflatex Thanks, Rajarshi -- http://mail.python.org/mailman/listinfo/python-list