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

Chris Angelico rosuav at gmail.com
Fri Jan 8 11:16:35 EST 2016


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"]?

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.

ChrisA



More information about the Python-list mailing list