Converting Diff Output to XML?
What would be the best way to convert the regular (unix) diff output into XML? Are there any libraries at all which might help? -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting Diff Output to XML?
That looks very good :)Thanks a ton! On 6/27/07, Yongjian Xu <[EMAIL PROTECTED]> wrote: gnosis has a converter for ASCII file to xml file, its called txt2dw.py. give it a try. -- Jim On 6/26/07, Debajit Adhikary <[EMAIL PROTECTED]> wrote: > > What would be the best way to convert the regular (unix) diff output > into XML? > Are there any libraries at all which might help? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Yongjian (Jim) Xu === Sysops -- http://mail.python.org/mailman/listinfo/python-list
Cannot parse simple entity references using xml.sax
I'm writing a SAX parser using Python and need to parse XML with entity references. <> Only the last entity reference gets parsed. Why are startEntity() and endEntity() never called? I'm using the following code: http://pastie.textmate.org/62610 -- http://mail.python.org/mailman/listinfo/python-list
python-list@python.org
I've written a SAX XML parser and cannot seem to be able to parse simple entity references e.g. < abc > It looks the XML parser that i'm using hasn't implemented the startEntity() and endEntity() methods. How do I parse such simple entity references using Python? - The code I'm using is: parser = make_parser() saxRssParser = SaxRssParser() # Implementation parser.setContentHandler(saxRssParser) parser.setProperty(handler.property_lexical_handler, saxRssParser) # For cdata, comments etc. parser.parse(filename) - Debajit -- http://mail.python.org/mailman/listinfo/python-list
Appending a list's elements to another list using a list comprehension
I have two lists: a = [1, 2, 3] b = [4, 5, 6] What I'd like to do is append all of the elements of b at the end of a, so that a looks like: a = [1, 2, 3, 4, 5, 6] I can do this using map(a.append, b) How do I do this using a list comprehension? (In general, is using a list comprehension preferable (or more "pythonic") as opposed to using map / filter etc.?) -- http://mail.python.org/mailman/listinfo/python-list
Re: Appending a list's elements to another list using a list comprehension
On Oct 17, 4:41 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Wed, 2007-10-17 at 20:27 +, Debajit Adhikary wrote: > > I have two lists: > > > a = [1, 2, 3] > > b = [4, 5, 6] > > > What I'd like to do is append all of the elements of b at the end of > > a, so that a looks like: > > > a = [1, 2, 3, 4, 5, 6] > > > I can do this using > > > map(a.append, b) > > > How do I do this using a list comprehension? > > You don't. > > > (In general, is using a list comprehension preferable (or more > > "pythonic") as opposed to using map / filter etc.?) > > In general, a list comprehension is more Pythonic nowadays, but in your > particular case the answer is neither map nor a list comprehension, it's > this: > > a += b > > HTH, > > -- > Carsten Haesehttp://informixdb.sourceforge.net Thanks a ton :) What in general is a good way to learn about little things like these? (I'm fairly new to the language) A google search for 'python list methods" did not turn up the + operator anywhere for me. Where could I find the official documentation for built in structures like the list? (I just noticed that the + operator for lists is mentioned in Beazley's Python Essential Reference -- in the opening pages, which I didn't look at when I was writing the earlier code.) How does "a.extend(b)" compare with "a += b" when it comes to performance? Does a + b create a completely new list that it assigns back to a? If so, a.extend(b) would seem to be faster. How could I verify things like these? -- http://mail.python.org/mailman/listinfo/python-list
Re: Appending a list's elements to another list using a list comprehension
On Oct 17, 5:40 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > To answer your question though: a += b is *not* the same as a = a + b. > The latter would create a new list and assign it to a, whereas a += b > updates a in-place. I know I'm being a little finicky here, but how would someone know that a+=b is not the same as a=a+b? Any documentation or reference that mentions this? > Use a += b rather than a.extend(b): I'm not sure what I was thinking. > Anyway, look at 'timeit' to see how to measure things like this, but > my advice would be not to worry and to write the most readable code - > and only optimise if your code's runnign too slowly. I understand. Thanks :) At the same time, however, as someone new learning the language, I feel it always helps to know what the best practices and patterns are at the very outset (at least for someone who chooses to become a good programmer in that language). I mean, for me it's like this, I just don't want to get the work done, I would really want to know why I do something a certain way and not some other way :) -- http://mail.python.org/mailman/listinfo/python-list
Best way to generate alternate toggling values in a loop?
I'm writing this little Python program which will pull values from a database and generate some XHTML. I'm generating a where I would like the alternate 's to be and What is the best way to do this? I wrote a little generator (code snippet follows). Is there a better (more "Pythonic") way to do this? # Start of Code def evenOdd(): values = ["Even", "Odd"] state = 0 while True: yield values[state] state = (state + 1) % 2 # Snippet trClass = evenOdd() stringBuffer = cStringIO.StringIO() for id, name in result: stringBuffer.write(''' %d %s ''' % (trClass.next(), id, name)) # End of Code -- http://mail.python.org/mailman/listinfo/python-list
Re: Appending a list's elements to another list using a list comprehension
On Oct 18, 9:47 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > Debajit Adhikary <[EMAIL PROTECTED]> wrote: > > > How does "a.extend(b)" compare with "a += b" when it comes to > > performance? Does a + b create a completely new list that it assigns > > back to a? If so, a.extend(b) would seem to be faster. How could I > > verify things like these? > > That's what the timeit module is for, but make sure that the snippet > you're timing has no side effects (since it's repeatedly executed). > E.g.: > > brain:~ alex$ python -mtimeit -s'z=[1,2,3];b=[4,5,6]' > 'a=z[:];a.extend(b)' > 100 loops, best of 3: 0.769 usec per loop > brain:~ alex$ python -mtimeit -s'z=[1,2,3];b=[4,5,6]' 'a=z[:];a+=b' > 100 loops, best of 3: 0.664 usec per loop > brain:~ alex$ python -mtimeit -s'z=[1,2,3];b=[4,5,6]' > 'a=z[:];a.extend(b)' > 100 loops, best of 3: 0.769 usec per loop > brain:~ alex$ python -mtimeit -s'z=[1,2,3];b=[4,5,6]' 'a=z[:];a+=b' > 100 loops, best of 3: 0.665 usec per loop > brain:~ alex$ > > The repetition of the measurements show them very steady, so now you > know that += is about 100 nanoseconds faster (on my laptop) than extend > (the reason is: it saves the tiny cost of looking up 'extend' on a; to > verify this, use much longer lists and you'll notice that while overall > times for both approaches increase, the difference between the two > approaches remains about the same for lists of any length). > You can find more details on commandline use of timeit at > <http://docs.python.org/lib/node808.html> (see adjacent nodes in Python > docs for examples and details on the more advanced use of timeit inside > your own code) but I hope these indications may be of help anyway. Thanks for the wonderful explanation on timeit. Thats one more tool now in my arsenal :P -- http://mail.python.org/mailman/listinfo/python-list