Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8439019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:53:20+00:00 2026-06-10T07:53:20+00:00

Today I see that – python add _$CLASSNAME$ to methods with name with __

  • 0

Today I see that – python add _$CLASSNAME$ to methods with name with __.

Simple example:

>>> class A:  
...     def a(self):  
...         self.b()  
...     def b(self):  
...         print('A.b')  
...           
>>> class B(A):  
...     def b(self):  
...         print('B.b')  
...           
>>> B().a()  
B.b

That work, but:

>>> class A:  
...     def a(self):  
...         self.__b()  
...     def __b(self):  
...         print('A.b')  
...           
>>> class B(A):  
...     def __b(self):  
...         print('B.b')  
...           
>>> B().a()  
A.b

Why? I don’t know, so I dir’ed it. Here it is:

>>> print([fn for fn in dir(B) if fn[-2:] != '__'])
['_A__b', '_B__b', 'a']

Why python do that? Is there way to bypass that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:53:22+00:00Added an answer on June 10, 2026 at 7:53 am

    It’s called name mangling and done to prevent accidental name collisions with parent and child classes. You cannot (and should not, a lot of perfectly fine code uses it) disable it. You can circumvent it, but you should not do that either (it’s extremely ugly, you can avoid it, and when you need access to it you shouldn’t permit name mangling in the first place). Just use a single underscore for private functions you want to use anywhere but immediately inside the class.

    See the tutorial but ignore any reference to this denoting a “private” variable. That’s not what it’s used for unless you use private in the C++/Java/C#/… sense of private variables (as opposed to protected which are visible to child classes) being hidden from child classes. Even then it’s a flawed analogy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today, I have made an error that frustrated me for hours to see what
Today I see that an .ldf file of a SQL Server database is 66
When doing a simple performance measurement, I was astonished to see that calling String.IndexOf(char)
I have a method in my class that defines what today is. class Practice
Today I was walking at the MSDN Forums and I see two very strange
I have small query today I happen to see when I typed a website
today I have coded a test case for my application, to see how transactions
Today I ran into something a bit weird. I used mini-profiler to see the
Just posting the solution I worked out today. See my answer below. If you
I just started getting this error today, seemingly out of nowhere. Any one see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.