dynamism

Steven_Shaw at adc.com Steven_Shaw at adc.com
Tue Sep 10 07:19:26 CEST 2002


>> I've been away from Python for awhile and I'm wondering whether Python got
>> less "dynamic" while I was away.
>>
>> I thought you could just extend an object's attributes at
>> run-time like this:
>>
>> >>> p = object()
>> >>> p.x = 1
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> AttributeError: 'object' object has no attribute 'x'
>
>object is the base type of new-style classes.  Try something like this
>instead:
>
>>>> class foo:pass
>...
>>>> f = foo()
>>>> f.x = 1
>>>> f.x
>1

Thanks!

>
>Or 'class foo(object):pass' works too.
>
>// m






More information about the Python-list mailing list