471,872 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,872 software developers and data experts.

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 1250
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
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.