hasattr + __getattr__: I think this is Python bug
Robert Kern
robert.kern at gmail.com
Tue Jul 20 12:05:19 EDT 2010
On 7/20/10 6:59 AM, dmitrey wrote:
> On Jul 20, 1:37 pm, Chris Rebert<c... at rebertia.com> wrote:
>> Least ugly suggestion: Just don't use hasattr(); use your `x in
>> dir(y)` trick instead.
>
> something in dir() consumes O(n) operations for lookup, while hasattr
> or getattr() require O(log(n)). It matters for me, because it's inside
> deeply nested mathematical computations FuncDesigner is made for.
I'm not sure where you are getting log(n) from, but regardless, if you have so
many attributes that the O() matters more than the constant, you have more
problems than this.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list