Is it ok to use --> obj = object()?

M.E.Farmer mefjr75 at hotmail.com
Mon Oct 18 05:57:59 EDT 2004


aurora <aurora00 at gmail.com> wrote in message 
> Sometimes I find it useful to create an instance of some dummy class so  
> that I can bind abitrary attributes to it. I sometimes prefer this to  
> mapping object.
>
> >>> class A: pass
>  ...
> >>> a = A()
> >>> a.x = 1
> 
> >>> class B(object): pass
>  ...
> >>> b = B()
> >>> b.x = 1
>
> Rather that creating a dummy class, why not just instantiate from the  
> object class? However:

> >>> obj = object()
> >>> obj.x = 1

> I know I must have misunderstood something. Can you tell me what was wrong?

This is deja vu!
    You really should do a search before asking this.
It was discussed just a few days ago.
The answer is you can't do that.
object() isn't bent like that.
The internals just aren't there.
It cannot be used as a 'Bunch'.
Just use classes.
HTH, 
    M.E.Farmer



More information about the Python-list mailing list