Cool object trick

Fredrik Lundh fredrik at pythonware.com
Sat Dec 18 03:35:49 EST 2004


Bengt Richter wrote:

> >>> m = object()
> >>> m.title = 'not so fast ;-)'
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'object' object has no attribute 'title'

>>> m = object()
>>> m.title = 'yeah, that's stupid'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'object' object has no attribute 'title'

>>> class m: pass
>>> m.title = 'this works better'

>>> class result: pass
>>> m = result()
>>> m.title = 'this also works, and is a bit less obscure'

</F> 






More information about the Python-list mailing list