accessing an object instance by only having one of its attribute values

Bruno Desthuilliers bruno.42.desthuilliers at
Tue Jul 10 12:52:52 CEST 2007

mshiltonj a écrit :
> On Jul 8, 8:29 pm, Paul McGuire <p... at> wrote:
>> On Jul 8, 2:11 pm, mshiltonj <mshilt... at> wrote:
>> I have some comments on the Pythonicity of your suggestions.  Same
>> assumption, object attr is a unique key of some sort.  How to create
>> the dict of objects, and how to retrieve an object by key.
>> -- Paul
> I was probably being overly helpful, in a bad way. I'm new to python,
> I'm not very pythonic yet, and still learning the python idioms.
> Not sure why I slipped into the habit of testing for None, though. :-(
> Probably a perl thing, where I'm regularly testing for defined-ness.
> "if ($foo)" is different than "if (defined $foo)"

I'm not sure about the exact meaning of "defined-ness" in Perl, but in 
Python, trying to access a non-existing name - which is not the same 
thing as a name bound to None - will raise a NameError.

And while we're at it, you definitively don't need the parens around the 

More information about the Python-list mailing list