A
AlienBaby
Hi,
I'm just wondering why something is so, and whats going on under the
hood.
Now and again I use something like
class empty(object):
pass
simply so I can make an instance, and set some attributes on it.
a=empty()
a.whatever=something
Poking around with this, I assumed I could instead say
a=object()
a.whatever=something
but I get an attribute error. 'object object has no attribute
whatever'
I tried setattr() but get the same result.
So, it seems to me there is something special about instances of
object, and making an empty class that inherits from object, or
creating an instance of that class, is doing some 'magic' somewhere
that enables setting attributes etc..
Whats actually going on here, and why?
Matt.
I'm just wondering why something is so, and whats going on under the
hood.
Now and again I use something like
class empty(object):
pass
simply so I can make an instance, and set some attributes on it.
a=empty()
a.whatever=something
Poking around with this, I assumed I could instead say
a=object()
a.whatever=something
but I get an attribute error. 'object object has no attribute
whatever'
I tried setattr() but get the same result.
So, it seems to me there is something special about instances of
object, and making an empty class that inherits from object, or
creating an instance of that class, is doing some 'magic' somewhere
that enables setting attributes etc..
Whats actually going on here, and why?
Matt.