Problem of Readability of Python

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Oct 18 06:24:59 EDT 2007


On Wed, 17 Oct 2007 15:01:09 -0700, kiilerix wrote:

> On Oct 17, 9:11 pm, "Chris Mellon" <arkanes at gmail.com> wrote:
>> On 10/17/07, kiilerix at gmail.com <kiilerix at gmail.com> wrote:
>> > >>> o = object()
>> > >>> o.foo = 7
>>
>> What makes you think it can't be instantiated directly? You just did
>> it. It's not, however, suitable for use as an arbitrary thing to stick
>> attributes on.
>>
>> Which is a little sad, but a necessary requirement for things like
>> int() and str() to be small and fast.
> 
> So it's an optimization with side effects, giving a special case where
> the simple and otherwise "right" way to do it doesn't work? Too bad :-
> (
> 
> Ok; I'll continue to create dummy classes inheriting from object. And
> hope that one day it will be simpler.

I'm using the following "dummy" class with a little extra functionality:

def Bunch(object):
    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

person = Bunch(name='Eric', age=42)
print person.name
point = Bunch(x=4711, y=23)

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list