dynamism

Steven Shaw steven_shaw at adc.com
Mon Sep 9 23:23:55 EDT 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'

I thought that you could access dictionary values with object syntax:

>>> x = { 'a': 1, 'b':2 }
>>> x
{'a': 1, 'b': 2}
>>> x.a
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'dict' object has no attribute 'a'

Maybe you could never do this as shown but I'm sure there were ways of getting
this effect. Anyone care to remind me?

Cheers, Steve.



More information about the Python-list mailing list