469,349 Members | 1,584 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

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

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

Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'object' object has no attribute 'x'
I know I must have misunderstood something. Can you tell me what was wrong?
Jul 18 '05 #1
1 1211
aurora <au******@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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Craig Lister | last post: by
2 posts views Thread by David Thielen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.