CPython Class variable exposed to Python is altered.

Vincent Vande Vyvre vincent.vande.vyvre at telenet.be
Wed Apr 12 02:57:07 EDT 2017


Hi,

Learning CPython, I've made this simple exercice, a module test which 
contains an object Test.

The object Test has an attribute name, fixed at instanciation.

So, I try my code with a script:

-------------------------------------------
from test import Test

for n in ("The name", "Foo", "Spam"):
     t = Test(n)
     print("%s --> %s" %(n, t.name))
-------------------------------------------

And the return:

Uhe name --> Uhe name
Goo --> Goo
Tpam --> Tpam

As we can see, the first letter is changed with the next letter in 
alphabetical order, but not only for the attribute name, also for the 
reference n.

Same into a console:

(py352_venv) vincent at djoliba:~/CPython/py352_venv/pydcraw$ python
Python 3.5.2 (default, Dec 19 2016, 11:46:33)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> from test import Test
 >>> for n in ("The name", "Foo", "Spam"):
...     t = Test(n)
...     print("%s --> %s" %(n, t.name))
...
Uhe name --> Uhe name
Goo --> Goo
Tpam --> Tpam


I'm working in a venv.

The testmodule.c is attached.


The setup.py
------------------------------------------------
from distutils.core import setup, Extension
setup(name="test", version="1.0",
       ext_modules=[
          Extension("test", ["testmodule.c"],
                    libraries=[])
          ])
------------------------------------------------


Best,


Vincent



More information about the Python-list mailing list