setattr using invalid attribute names - bug or feature?

Gerson Kurz gerson.kurz at
Mon Jun 14 16:22:17 CEST 2004

I stumbled across this (while using my homebrewn enum class):

    class test:

    instance = test()
    setattr(instance, "THIS :*2+~# IS OBVIOUSLY INVALID", 123)

I would've expected some kind of error message here when calling
setattr(); after all, its not a regular attribute? Plus, documentation

 Set a named attribute on an object; setattr(x, 'y', v) is equivalent
    ``x.y = v''.

and you cannot write this:

instance.THIS :*2+~# IS OBVIOUSLY INVALID = 123

(oh, and its: PythonWin 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200
32 bit (Intel)] on win32.)

More information about the Python-list mailing list