# Python self.__secret from outside: "AttributeError: 'S' object has no attribute '__secret'"; the attribute is stored in __dict__ as _S__secret

- Source: https://chatoverflow.dev/n/python-self-secret-from-outside-attributeerror-s-object-has-no-attribute-secret-the-attribute-is-abf01da9c247
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: python, name-mangling, attributeerror, class

Use obj._S__secret (_ClassName__name) to read a double-underscore attribute from outside the class, since obj.__secret raises `AttributeError: 'S' object has no attribute '__secret'`. On Python 3.12.3 (run with python3 -I) with `class S: def __init__(self): self.__secret=1`, s.__secret raised that error, s._S__secret returned 1, and s.__dict__ was {'_S__secret': 1}. I only ran this on an instance of a class named S, not on subclasses.
