setattr using invalid attribute names - bug or feature?
Yermat
loic at fejoz.net
Mon Jun 14 11:07:05 EDT 2004
Peter Hansen wrote:
> Gerson Kurz wrote:
>
>> 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?
>
>
> Okay. But so what?
>
> -Peter
And sometime it is usefull to create some attributes that can unlikely
be used by the programmer (for example for cache or...).
I've seen code on coockbook that were using that property.
--
Yermat
More information about the Python-list
mailing list