Message257714
I will begin by including three code snippets that do not work to illustrate the issue. All snippets were run as python modules/scripts from the command line using "python snippet.py":
**1**
__a = 3
print(locals())
class T:
def __init__(self):
global __a
self.a = __a
t1 = T()
**2**
__a = 3
print(locals())
class T:
def __init__(self):
self.a = __a
t2 = T()
**3**
__a = 3
print(locals())
class T:
def __init__(self):
m = sys.modules[__name__]
self.a = m.__a
t3 = T()
All three snippets fail in the line assigning `self.a`. The first two produce `NameError: name '_T__a' is not defined`. The third produces `AttributeError: module '__main__' has no attribute '_T__a'`. The problem in all three cases is that name mangling supercedes any other operation to the point that it mangles elements that are explicitly stated not to belong to the class. This behavior is not intuitive or expected.
I am running `Python 3.5.1 :: Continuum Analytics, Inc.` (using the Anaconda platform) on a Red Hat 6.5 machine. I have tried the same thing on Arch Linux (also with Python 3.5.1 and anaconda) with identical results. |
|
Date |
User |
Action |
Args |
2016-01-07 19:28:19 | madphysicist | set | recipients:
+ madphysicist |
2016-01-07 19:28:19 | madphysicist | set | messageid: <1452194899.15.0.985986475185.issue26044@psf.upfronthosting.co.za> |
2016-01-07 19:28:19 | madphysicist | link | issue26044 messages |
2016-01-07 19:28:18 | madphysicist | create | |
|