Unable to access module attribute with underscores in class method, Python 3

Steven D'Aprano steve at pearwood.info
Fri Jan 8 20:25:12 EST 2016


On Sat, 9 Jan 2016 03:16 am, Chris Angelico wrote:

> On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano <steve at pearwood.info>
> wrote:
>> If you absolutely insist that you must must must continue to use a double
>> underscore name, you could also try this:
>>
>> py> __a = 1
>> py> class Test:
>> ...     def method(self):
>> ...             x = eval("__a")
>> ...             print(x)
>> ...
>> py> Test().method()
>> 1
>>
>>
>> But don't do that.
> 
> Seriously? You consider that less bad than globals()["__a"]?

No. That's why I said "don't do that" rather than "you should do this" :-)


> But all of this is craziness to support craziness. It's not asking
> which inmate should run the asylum - it's asking which of my multiple
> personalities should be elected fourteen-year-old queen.

Loretta, surely.




-- 
Steven




More information about the Python-list mailing list