<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Seeking Elegant Pythonic Solution</title>
	<atom:link href="http://www.protocolostomy.com/2010/02/01/seeking-elegant-pythonic-solution/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.protocolostomy.com/2010/02/01/seeking-elegant-pythonic-solution/</link>
	<description>Made with only the finest 1's and 0's</description>
	<lastBuildDate>Thu, 26 Jan 2012 21:20:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Tom Lynn</title>
		<link>http://www.protocolostomy.com/2010/02/01/seeking-elegant-pythonic-solution/comment-page-1/#comment-34676</link>
		<dc:creator>Tom Lynn</dc:creator>
		<pubDate>Thu, 11 Feb 2010 10:45:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=715#comment-34676</guid>
		<description>... or if you really want attribute access use the Python Cookbook Bunch recipe:

  import lxml.html
  
  class Result(object):
      def __init__(self, pairs):
          self.__dict__.update(pairs)
  
  results = [Result((node.tag, node.text_content()) for node in result)
             for result in lxml.html.fromstring(xml).xpath(&#039;//result&#039;)]

The choice between using node.text and node.text_content() depends how you want to handle unexpected child nodes.  If you might get embedded HTML (e.g. a sup tag to superscript a trademark sign), use node.text_content() as above, otherwise you&#039;re ok with node.text.</description>
		<content:encoded><![CDATA[<p>&#8230; or if you really want attribute access use the Python Cookbook Bunch recipe:</p>
<p>  import lxml.html</p>
<p>  class Result(object):<br />
      def __init__(self, pairs):<br />
          self.__dict__.update(pairs)</p>
<p>  results = [Result((node.tag, node.text_content()) for node in result)<br />
             for result in lxml.html.fromstring(xml).xpath('//result')]</p>
<p>The choice between using node.text and node.text_content() depends how you want to handle unexpected child nodes.  If you might get embedded HTML (e.g. a sup tag to superscript a trademark sign), use node.text_content() as above, otherwise you&#8217;re ok with node.text.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Lynn</title>
		<link>http://www.protocolostomy.com/2010/02/01/seeking-elegant-pythonic-solution/comment-page-1/#comment-34662</link>
		<dc:creator>Tom Lynn</dc:creator>
		<pubDate>Wed, 10 Feb 2010 19:48:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=715#comment-34662</guid>
		<description>import lxml.html

  xml = lxml.html.fromstring(xml)
  results = [dict((node.tag, node.text_content()) for node in result)
             for result in xml.xpath(&#039;//result&#039;)]</description>
		<content:encoded><![CDATA[<p>import lxml.html</p>
<p>  xml = lxml.html.fromstring(xml)<br />
  results = [dict((node.tag, node.text_content()) for node in result)<br />
             for result in xml.xpath('//result')]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://www.protocolostomy.com/2010/02/01/seeking-elegant-pythonic-solution/comment-page-1/#comment-34247</link>
		<dc:creator>James</dc:creator>
		<pubDate>Thu, 04 Feb 2010 05:19:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=715#comment-34247</guid>
		<description>While it looks like you already have a solution, I tend to use BeautifulStoneSoup for XML parsing like this:

http://gist.github.com/294341

BeautifulStoneSoup gives you Unicode *and* the class it gives you appears to inherit all the standard methods for type str.

Hope that helps!</description>
		<content:encoded><![CDATA[<p>While it looks like you already have a solution, I tend to use BeautifulStoneSoup for XML parsing like this:</p>
<p><a href="http://gist.github.com/294341" rel="nofollow">http://gist.github.com/294341</a></p>
<p>BeautifulStoneSoup gives you Unicode *and* the class it gives you appears to inherit all the standard methods for type str.</p>
<p>Hope that helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin Horn</title>
		<link>http://www.protocolostomy.com/2010/02/01/seeking-elegant-pythonic-solution/comment-page-1/#comment-34037</link>
		<dc:creator>Kevin Horn</dc:creator>
		<pubDate>Tue, 02 Feb 2010 06:13:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=715#comment-34037</guid>
		<description>I probably would have used lxml.etree to get a list of &quot;result&quot; elements, and iterated over each of those to get a list of the children of each, then created a dictionary from the keys (elem.tag), and values (elem.text) and then proceeded from there.  If this makes any sense to you, then you&#039;ve probbaly stayed up too late.  I know I have. :)

Alex&#039;s solution is probably better though.</description>
		<content:encoded><![CDATA[<p>I probably would have used lxml.etree to get a list of &#8220;result&#8221; elements, and iterated over each of those to get a list of the children of each, then created a dictionary from the keys (elem.tag), and values (elem.text) and then proceeded from there.  If this makes any sense to you, then you&#8217;ve probbaly stayed up too late.  I know I have. <img src='http://www.protocolostomy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Alex&#8217;s solution is probably better though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Foord</title>
		<link>http://www.protocolostomy.com/2010/02/01/seeking-elegant-pythonic-solution/comment-page-1/#comment-34021</link>
		<dc:creator>Michael Foord</dc:creator>
		<pubDate>Tue, 02 Feb 2010 00:59:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.protocolostomy.com/?p=715#comment-34021</guid>
		<description>Whilst you *should* use the solution suggested by Alex, I still like my horrid little one liner with reduce and a lambda:

    reduce(lambda result, attr: getattr(result, attr), [the_object] + list(the_string.split(&#039;.&#039;)))</description>
		<content:encoded><![CDATA[<p>Whilst you *should* use the solution suggested by Alex, I still like my horrid little one liner with reduce and a lambda:</p>
<p>    reduce(lambda result, attr: getattr(result, attr), [the_object] + list(the_string.split(&#8216;.&#8217;)))</p>
]]></content:encoded>
	</item>
</channel>
</rss>

