object as bunch (WAS Re: End of file)

S

Steven Bethard

Alex Martelli said:
If an object() could be used as a Bunch I do think it would be
reasonably common. But it can't, so I insist that its role as
sentinel/placeholder is the only possibility.

Anyone know what the design goal was that caused object not to be written to
be used as a Bunch?

I'm not suggesting that I'd want to be able to set attributes from outside the
class -- the fact that x23.foo = 23 is an AttributeError if x23 does not have
a foo attribute is a Good Thing, IMHO -- but I can see that a **kwds
constructor like dict() has might be useful:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'object' object has no attribute 'foo3'

If object was a Bunch, you could also set the fields of a class in the call to
object's __init__.
.... def __init__(self, foo23, foo57=None):
.... super(C, self).__init__(foo23=foo23, foo57=foo57)
....1

Don't know if the fields behavior here really gains you anything, but it would
be another side effect of object being a Bunch.

I have wanted from time to time to have a Bunch object. Of course it's only 3
lines of code to roll your own... But I wouldn't mind hearing about the
reasoning behind making object as it is...

Steve
 
A

Alex Martelli

Steven Bethard said:
Anyone know what the design goal was that caused object not to be written to
be used as a Bunch?

I believe the point was to not weigh down each instance of object with
it own dictionary, since a dict takes quite a few bytes of RAM. I could
well be wrong, though.


Alex
 
M

Michael Hoffman

Alex said:
I believe the point was to not weigh down each instance of object with
it own dictionary, since a dict takes quite a few bytes of RAM. I could
well be wrong, though.

Yeah, but did anyone expect object to ever be instantiated directly?
Just askin'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,684
Latest member
sparada

Latest Threads

Top