<?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"
	>
<channel>
	<title>Comments on: Top Tips for the Python Programmer</title>
	<atom:link href="http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/</link>
	<description>Failing better at understanding the past</description>
	<pubDate>Thu, 20 Nov 2008 17:11:57 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Daniel Cousineau</title>
		<link>http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/#comment-14180</link>
		<dc:creator>Daniel Cousineau</dc:creator>
		<pubDate>Wed, 19 Nov 2008 00:32:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/#comment-14180</guid>
		<description>Thanks!

It'd be nice to have even something like the isset() function PHP has... or add a function to the core list API to the extent of .has_key(). Dictionaries have a .has_key()...</description>
		<content:encoded><![CDATA[<p>Thanks!</p>
<p>It&#8217;d be nice to have even something like the isset() function PHP has&#8230; or add a function to the core list API to the extent of .has_key(). Dictionaries have a .has_key()&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Vasile</title>
		<link>http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/#comment-14165</link>
		<dc:creator>James Vasile</dc:creator>
		<pubDate>Sun, 09 Nov 2008 15:58:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/#comment-14165</guid>
		<description>I believe this code does what you want with less fuss:

&lt;code&gt;if 'min' in element.attributes and element.attributes['min']:&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I believe this code does what you want with less fuss:</p>
<p><code>if 'min' in element.attributes and element.attributes['min']:</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gavin Robinson</title>
		<link>http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/#comment-13836</link>
		<dc:creator>Gavin Robinson</dc:creator>
		<pubDate>Mon, 03 Mar 2008 16:50:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/#comment-13836</guid>
		<description>As far as I can tell Python has nothing like &lt;code&gt;defined&lt;/code&gt;. The &lt;code&gt;hasattr()&lt;/code&gt; function is useful for finding if an object has the specified attribute but there doesn't seem to be an equivalent for any of the other exceptions.

Where I'm running into problems is with getting XML attributes. I'm using minidom to parse XML files. Each XML element is represented by a Python object. The XML attributes are in a map where the attribute name is the key. I want to know if an element has a certain attribute: it might, but it doesn't have to. For example if a value is stated in the manuscript it goes in the content of the XML tag, but if the value is uncertain the tag has min and max attributes.

So this code would throw an exception if the element doesn't have a min attribute:

&lt;code&gt;
if element.attributes['min']:
    #do something with the value of min
&lt;/code&gt;

I can use

&lt;code&gt;if len(element.attributes) == 0:&lt;/code&gt;

to see if it has no attributes, but what if it has some attributes but not the ones I'm interested in?

I wouldn't be surprised if there was an easier way to do this that I don't know about, but so far the exception thing is working.</description>
		<content:encoded><![CDATA[<p>As far as I can tell Python has nothing like <code>defined</code>. The <code>hasattr()</code> function is useful for finding if an object has the specified attribute but there doesn&#8217;t seem to be an equivalent for any of the other exceptions.</p>
<p>Where I&#8217;m running into problems is with getting XML attributes. I&#8217;m using minidom to parse XML files. Each XML element is represented by a Python object. The XML attributes are in a map where the attribute name is the key. I want to know if an element has a certain attribute: it might, but it doesn&#8217;t have to. For example if a value is stated in the manuscript it goes in the content of the XML tag, but if the value is uncertain the tag has min and max attributes.</p>
<p>So this code would throw an exception if the element doesn&#8217;t have a min attribute:</p>
<p><code><br />
if element.attributes['min']:<br />
    #do something with the value of min<br />
</code></p>
<p>I can use</p>
<p><code>if len(element.attributes) == 0:</code></p>
<p>to see if it has no attributes, but what if it has some attributes but not the ones I&#8217;m interested in?</p>
<p>I wouldn&#8217;t be surprised if there was an easier way to do this that I don&#8217;t know about, but so far the exception thing is working.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Brumfield</title>
		<link>http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/#comment-13835</link>
		<dc:creator>Ben Brumfield</dc:creator>
		<pubDate>Mon, 03 Mar 2008 15:58:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.investigations.4-lom.com/2008/03/03/top-tips-for-the-python-programmer/#comment-13835</guid>
		<description>Doesn't Python have anything akin to the &lt;code&gt;defined?&lt;/code&gt; operator in Ruby?  

Also, under what circumstances are you running into this problem?  Usually this kind of thing only comes up when meta-programming.</description>
		<content:encoded><![CDATA[<p>Doesn&#8217;t Python have anything akin to the <code>defined?</code> operator in Ruby?  </p>
<p>Also, under what circumstances are you running into this problem?  Usually this kind of thing only comes up when meta-programming.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
