[issue43519] access python private variable

David Elmakias report at bugs.python.org
Tue Mar 16 13:20:30 EDT 2021


New submission from David Elmakias <marko9387 at gmail.com>:

It might be my lack of knowledge in python, however I find this behavior a bit strange.

By declaring a private variable in a class, python creates an attribute with the name '_<ClassName>__<PrivateVariableName>'.
Both are located on a different location in memory.

I found that by assigning data to the created variable with the exact name/notation '_<ClassName>__<PrivateVariableName>' I changed the private variable data.

----------
components: Build
files: access_class_private_variable.py
messages: 388862
nosy: AluminumPirate
priority: normal
severity: normal
status: open
title: access python private variable
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file49878/access_class_private_variable.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43519>
_______________________________________


More information about the Python-bugs-list mailing list