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

2016-01-08 Thread Steven D'Aprano
On Sat, 9 Jan 2016 03:16 am, Chris Angelico wrote: > On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano > 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):

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

2016-01-08 Thread Chris Angelico
On Sat, Jan 9, 2016 at 3:07 AM, Steven D'Aprano 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)

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

2016-01-08 Thread Steven D'Aprano
On Fri, 8 Jan 2016 03:14 am, Joseph Fox-Rabinovitz wrote: > Hi, > > I have a module attribute whose name starts with a pair of underscores. Don't do that. The way to flag a module-level variable as private is with a single leading underscore. Double-leading underscores are intended for use in c

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

2016-01-08 Thread Peter Otten
Joseph Fox-Rabinovitz wrote: > Hi, > > I have a module attribute whose name starts with a pair of underscores. I > am apparently unable to access it directly in a class method (within the > same module, but that is not relevant as far as I can tell). The following > bit of code illustrates the si

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

2016-01-08 Thread Joseph Fox-Rabinovitz
> On Thu, Jan 7, 2016 at 11:14 AM, Joseph Fox-Rabinovitz > wrote: > > Hi, > > I have a module attribute whose name starts with a pair of underscores. I am > apparently unable to access it directly in a class method (within the same > module, but that is not relevant as far as I can tell). The f

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

2016-01-08 Thread Joseph Fox-Rabinovitz
Hi, I have a module attribute whose name starts with a pair of underscores. I am apparently unable to access it directly in a class method (within the same module, but that is not relevant as far as I can tell). The following bit of code illustrates the situation: __a = 3 class B: def __init_