On Thu, Jan 21, 2010 at 6:23 AM, Gnarlodious <span dir="ltr"><<a href="mailto:gnarlodious@gmail.com">gnarlodious@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">This works! However I end up saying:</div>
<br>
d['Server'].Config.BaseURL<br>
<br>
to get the data, when I should be saying:<br>
<br>
Server.Config.BaseURL</blockquote><div><br></div><div>That's the thing: you should not actually be saying that.</div><div><br></div><div>d['Server'].Config.BaseURL is precisely what you should be saying.</div>

<div><br></div><div>You need to adjust your expectations to the language you are using and how it operates. Whatever aesthetic sense in you that is objecting to using a dictionary is something you just need to get past. If you don't like the dictionary getitem syntax, you can always do:</div>

<div><br></div><div><div>>>> class AttrDict(dict):</div><div>...     def __getattr__(self, key):</div><div>...             return self[key]</div><div>... </div><div>>>> a = AttrDict()</div><div>>>> a["test"] = 1</div>

<div>>>> a.test</div><div>1</div><div><br></div><div>Is there any real reason you can't write Servers["Server"].Config.BaseURL or Servers.Server.Config.BaseURL, or is it just an itch that's bugging you? If its the latter, then it's better to just not scratch it and it'll go away when you get more used to the language :)</div>

<div><br></div><div>Its not easy to do what you're asking for. People ask for it every once in awhile. But it's just not the Pythonic way to approach the problem, and while there are things you can do to accomplish it, they're hacks and are not guaranteed to work consistently. Its not even a oversight in Python, something the devs never considered: its intentionally designed to be this way.</div>

<div><br></div><div>How come a dictionary (or class as above) isn't good enough?</div></div></div><br clear="all"><div name="mailplane_signature">--S</div>