Python 3.1, object, and setattr()

Ethan Furman ethan at
Thu Apr 1 15:46:33 CEST 2010


Perhaps I woke up too early this morning, but this behaviour has me baffled:

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

--> test = object()

--> setattr(test, 'example', 123)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'example'

Shouldn't setattr() be creating the 'example' attribute?  Any tips 
greatly appreciated!


More information about the Python-list mailing list