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 7082631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:04:41+00:00 2026-05-28T07:04:41+00:00

I am doing the python koan (for python 2.6) and ecnountered something I don’t

  • 0

I am doing the python koan (for python 2.6) and ecnountered something I don’t understand. One of the files has the following code in line 160:

class Dog(object):
    def __password(self):
        return 'password'

This

rover = Dog()
password = rover.__password()

results in an AttributeError. That is clear to me. (__password(self) is some kind of private method because of the leading two underscores).

But this

rover._Dog__password()

is a mystery to me. Could some one please explain to me how or why this works or better point me to the docs where this is described?

  • 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-28T07:04:42+00:00Added an answer on May 28, 2026 at 7:04 am

    Double underscore :

    Any identifier of the form __spam (at least two leading underscores,
    at most one trailing underscore) is textually replaced with
    _classname__spam, where classname is the current class name with leading underscore(s) stripped. This mangling is done without regard
    to the syntactic position of the identifier, so it can be used to
    define class-private instance and class variables, methods, variables
    stored in globals, and even variables stored in instances. private to
    this class on instances of other classes.

    So when you call the __methodname, it’s exactly a call to _classname__methodname. The result is an AttributeError

    Single underscore :

    Variables in a class with a leading underscore are simply to indicate to other programmers that the variable should be private. However, nothing special is done with the variable itself.

    Python documentation here :

    Python private variables documentation

    Complete post found here :

    What is the meaning of a single- and a double-underscore before an object name?

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

Sidebar

Related Questions

I am doing something like this in python class MyThread ( threading.Thread ): def
To do the equivalent of Python list comprehensions, I'm doing the following: some_array.select{|x| x
I'm doing a little python plasmoid that deals with remote resources. Here's the code
I often see python code that takes default arguments and has special behaviour when
I'm doing some Python coding in a clients code base and I stumbled on
The other day I was doing some Python benchmarking and I came across something
I can check for a module in Python doing something like: try: import some_module
I have a small project I am doing in Python using web.py. It's a
Python is doing string multiplication where I would expect it to do numeric multiplication,
What is the best way of doing this in Python? for (v = n

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.