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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:28:55+00:00 2026-05-14T00:28:55+00:00

I have a private method def __pickSide(self): in a parent class that I would

  • 0

I have a private method def __pickSide(self): in a parent class that I would like to override in the child class. However, the child class still calls the inherited def __pickSide(self):. How can I override the function? The child class’s function name is exactly the same as the parent’s function name.

  • 1 1 Answer
  • 1 View
  • 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-14T00:28:56+00:00Added an answer on May 14, 2026 at 12:28 am

    Let’s look at the easiest example:

    from dis import dis
    
    class A(object):
      def __pick(self):
          print "1"
    
      def doitinA(self):
          self.__pick()
    
    class B(A):
      def __pick(self):
          print "2"
    
      def doitinB(self):
          self.__pick()
    
    b = B()
    b.doitinA() # prints 1
    b.doitinB() # prints 2
    
    dis(A.doitinA)
    print
    dis(B.doitinB)
    

    The disassembly is as follows:

      8           0 LOAD_FAST                0 (self)
                  3 LOAD_ATTR                0 (_A__pick)
                  6 CALL_FUNCTION            0
                  9 POP_TOP
                 10 LOAD_CONST               0 (None)
                 13 RETURN_VALUE
    
     15           0 LOAD_FAST                0 (self)
                  3 LOAD_ATTR                0 (_B__pick)
                  6 CALL_FUNCTION            0
                  9 POP_TOP
                 10 LOAD_CONST               0 (None)
                 13 RETURN_VALUE
    

    As you can see, Python mangles function names that begin with two underscores (and accesses to such names!!) to a name that includes the class name – in this case _A__pick and _B__pick). That means that the class in which a function is defined determines which of the __pick methods is called.

    The solution is simple, avoid pseudo-private methods by removing the double underscores. For example, use _pick instead of __pick.

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

Sidebar

Related Questions

I have the following C# method: private string[] test() { } I would like
In my messages_controller I have the following private method: def find_message_or_404(slug) message = user.messages.find_by_slug(slug)
I'm trying to unit test a private method that I have attached to my
I have class which have one public method Start , one private method and
I have a private variable in my class: BOOL isEnabled; and a method: -(void)
I have a class whose new method has been made private because I want
I have a pretty standard authenticate method private def authenticate_user @current_user = User.find_by_authentication_token(params[:token]) unless
I have a couple of modules that extend method missing: module SaysHello def respond_to?(method)
I have the following controller: class FirstController < ApplicationController helper_method :contoller_method private def contoller_method
I have controller: class AccountController < ApplicationController def index end private def current_account @current_account

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.