setattr using invalid attribute names - bug or feature?

Gerson Kurz gerson.kurz at t-online.de
Mon Jun 14 10:22:17 EDT 2004


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

    class test:
        pass

    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
says

"
 Set a named attribute on an object; setattr(x, 'y', v) is equivalent
to
    ``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