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

  • SEARCH
  • Home
  • 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 6206021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:22:30+00:00 2026-05-24T05:22:30+00:00

Somebody was nice enough to explain to me that __method() mangles but instead of

  • 0

Somebody was nice enough to explain to me that __method() mangles but instead of bothering him further since there are a lot of other people who need help I was wondering if somebody could elaborate the differences further.

For example I don’t need mangling but does _ stay private so somebody couldn’t do instance._method()? Or does it just keep it from overwriting another variable by making it unique? I don’t need my internal methods “hidden” but since they are specific to use I don’t want them being used outside of the class.

  • 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-05-24T05:22:32+00:00Added an answer on May 24, 2026 at 5:22 am

    From PEP 8:

    • _single_leading_underscore: weak “internal use” indicator. E.g.

      from M import *

      does not import objects whose name starts with an underscore.

    • single_trailing_underscore_: used by convention to avoid conflicts with Python keyword, e.g.

      Tkinter.Toplevel(master, class_='ClassName')

    • __double_leading_underscore: when naming a class attribute, invokes name
      mangling (inside class FooBar, __boo becomes _FooBar__boo; see below).

    • __double_leading_and_trailing_underscore__: “magic” objects or
      attributes that live in user-controlled namespaces. E.g. __init__,
      __import__ or __file__. Never invent such names; only use them
      as documented.

    Also, from David Goodger’s Code Like a Pythonista:

    Attributes: interface, _internal, __private

    But try to avoid the __private form. I never use it. Trust me. If you
    use it, you WILL regret it later.

    Explanation:

    People coming from a C++/Java background are especially prone to
    overusing/misusing this “feature”. But __private names don’t work the
    same way as in Java or C++. They just trigger a name mangling whose
    purpose is to prevent accidental namespace collisions in subclasses:
    MyClass.__private just becomes MyClass._MyClass__private. (Note that
    even this breaks down for subclasses with the same name as the
    superclass, e.g. subclasses in different modules.) It is possible to
    access __private names from outside their class, just inconvenient and
    fragile (it adds a dependency on the exact name of the superclass).

    The problem is that the author of a class may legitimately think “this
    attribute/method name should be private, only accessible from within
    this class definition” and use the __private convention. But later on,
    a user of that class may make a subclass that legitimately needs
    access to that name. So either the superclass has to be modified
    (which may be difficult or impossible), or the subclass code has to
    use manually mangled names (which is ugly and fragile at best).

    There’s a concept in Python: “we’re all consenting adults here”. If
    you use the __private form, who are you protecting the attribute from?
    It’s the responsibility of subclasses to use attributes from
    superclasses properly, and it’s the responsibility of superclasses to
    document their attributes properly.

    It’s better to use the single-leading-underscore convention,
    _internal. “This isn’t name mangled at all; it just indicates to
    others to “be careful with this, it’s an internal implementation
    detail; don’t touch it if you don’t fully understand it”. It’s only a
    convention though.

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

Sidebar

Related Questions

Can somebody please explain me clearly by using some nice examples how c++ class
Somebody said that when your PHP code and application use global variables then it
Can somebody point me to a resource that explains how to go about having
Could somebody please name a few. I could given time, but this is for
I would like to know if somebody knows free custom nice controls for .NET
Django's internationalization is very nice (gettext based, LocaleMiddleware), but what is the proper way
Someone made a nice code for me, but after some changes to have the
do you have idea, if there would be some nice way to browse/log JMS
There is one aspect of TDD which I never fully understood. Suppose somebody asked
Somebody knows a nice program for creating database models supporting Osx and Linux? If

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.