<?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: Access Python Dictionary Keys As Properties</title>
	<atom:link href="http://parand.com/say/index.php/2008/10/13/access-python-dictionary-keys-as-properties/feed/" rel="self" type="application/rss+xml" />
	<link>http://parand.com/say/index.php/2008/10/13/access-python-dictionary-keys-as-properties/</link>
	<description>Parand Tony Darugar: A Cruel and Petty Dictator</description>
	<lastBuildDate>Tue, 17 Jan 2012 23:10:42 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Python编程资料 &#171; Crackerban Team</title>
		<link>http://parand.com/say/index.php/2008/10/13/access-python-dictionary-keys-as-properties/comment-page-1/#comment-337457</link>
		<dc:creator>Python编程资料 &#171; Crackerban Team</dc:creator>
		<pubDate>Thu, 20 Oct 2011 02:09:26 +0000</pubDate>
		<guid isPermaLink="false">http://parand.com/say/?p=695#comment-337457</guid>
		<description>[...] 封装字典结构使之可以通过实例属性方式访问的方法 [...]</description>
		<content:encoded><![CDATA[<p>[...] 封装字典结构使之可以通过实例属性方式访问的方法 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ygor Lemos</title>
		<link>http://parand.com/say/index.php/2008/10/13/access-python-dictionary-keys-as-properties/comment-page-1/#comment-318679</link>
		<dc:creator>Ygor Lemos</dc:creator>
		<pubDate>Tue, 03 May 2011 15:48:48 +0000</pubDate>
		<guid isPermaLink="false">http://parand.com/say/?p=695#comment-318679</guid>
		<description>You can also use one very quick solution:

class DictObj:
    def __init__(self, **entries): 
        self.__dict__.update(entries)

z = DictObj(**d)

z.name
z.mood</description>
		<content:encoded><![CDATA[<p>You can also use one very quick solution:</p>
<p>class DictObj:<br />
    def __init__(self, **entries):<br />
        self.__dict__.update(entries)</p>
<p>z = DictObj(**d)</p>
<p>z.name<br />
z.mood</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bigb</title>
		<link>http://parand.com/say/index.php/2008/10/13/access-python-dictionary-keys-as-properties/comment-page-1/#comment-312168</link>
		<dc:creator>bigb</dc:creator>
		<pubDate>Thu, 10 Mar 2011 14:51:13 +0000</pubDate>
		<guid isPermaLink="false">http://parand.com/say/?p=695#comment-312168</guid>
		<description>@Erich:

No need to call super().__getattr__ here. __getattr__ is called as a last resort, and the dict type doesn&#039;t implement __getattr__, so you know for sure that when you&#039;re in DictObj.__getattr__, the attribute has not been *and* won&#039;t be resolved upper in the __mro__. FWIW, this call will only raise an AttributeError (which is what you should do) but with a rather misleading message.</description>
		<content:encoded><![CDATA[<p>@Erich:</p>
<p>No need to call super().__getattr__ here. __getattr__ is called as a last resort, and the dict type doesn&#8217;t implement __getattr__, so you know for sure that when you&#8217;re in DictObj.__getattr__, the attribute has not been *and* won&#8217;t be resolved upper in the __mro__. FWIW, this call will only raise an AttributeError (which is what you should do) but with a rather misleading message.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erich</title>
		<link>http://parand.com/say/index.php/2008/10/13/access-python-dictionary-keys-as-properties/comment-page-1/#comment-182868</link>
		<dc:creator>Erich</dc:creator>
		<pubDate>Tue, 14 Oct 2008 18:01:34 +0000</pubDate>
		<guid isPermaLink="false">http://parand.com/say/?p=695#comment-182868</guid>
		<description>An alternative to this, which I&#039;ve used frequently is to inherit from the dict object itself. This allows for use of normal dict operations and methods and well.  This will cause strange errors if you expect your dict to contain keys that collide with the dict method names, however that limitation can be worked around depending on the specifics of the use-case.

It is particulary convenient when the dict in qustion is not yet populated
fully.

I know the following works in 2.4 and 2.5 (probably 2.6 but haven&#039;t tested it):

class DictObj(dict):
    def __getattr__(self, name):
        try:
            return self.__getitem__(name)
        except KeyError:
            return super(DictObj,self).__getattr__(name)</description>
		<content:encoded><![CDATA[<p>An alternative to this, which I&#8217;ve used frequently is to inherit from the dict object itself. This allows for use of normal dict operations and methods and well.  This will cause strange errors if you expect your dict to contain keys that collide with the dict method names, however that limitation can be worked around depending on the specifics of the use-case.</p>
<p>It is particulary convenient when the dict in qustion is not yet populated<br />
fully.</p>
<p>I know the following works in 2.4 and 2.5 (probably 2.6 but haven&#8217;t tested it):</p>
<p>class DictObj(dict):<br />
    def __getattr__(self, name):<br />
        try:<br />
            return self.__getitem__(name)<br />
        except KeyError:<br />
            return super(DictObj,self).__getattr__(name)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

