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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:06:20+00:00 2026-05-24T00:06:20+00:00

I have the following code: class A(object): def __init__(self): self.name = A super(A, self).__init__()

  • 0

I have the following code:

class A(object):
    def __init__(self):
        self.name = "A"
        super(A, self).__init__()

    def Update(self):
        print "Update A"
        self.PickTarget()

    def PickTarget(self):
        print "PickTarget A"

class B(object):
    def __init__(self):
        self.name = "B"
        super(B, self).__init__()

    def Update(self):
        print "Update B"
        self.PickTarget()

    def PickTarget(self):
        print "PickTarget B"

class C(A, B):
    def __init__(self):
        super(C, self).__init__()

    def Update(self, useA):
        if useA:
            A.Update(self)
        else:
            B.Update(self)

c = C()

c.Update(useA = True)
# prints: 
# Update A
# PickTarget A

c.Update(useA = False)
# prints:
# Update B
# PickTarget A

Why does calling C.Update with useA=False still call into A.PickTarget? How can I make this work how I want it to work (ie B.Update always calls into B.PickTarget)? I’m sure this has been asked before but my searching turned up nothing – probably because I don’t know what to search for.

  • 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-24T00:06:21+00:00Added an answer on May 24, 2026 at 12:06 am

    It’s because A is before B in C‘s base classes.

    You need to use B.PickTarget(self) rather than self.PickTarget() in B.Update(self) to get this behavior. Otherwise, switch A and B in C‘s definition.

    Edit:

    If the intended behavior is for B to always call methods in B and for A to always call methods in A, it’s correct to use A.method(self) instead of self.method(), as the second form doesn’t imply that method is in A.

    You should redesign your classes. A should have a move method that moves the robot randomly and define it’s other basic behavior. B should be a subclass of A and should have a move method that calls super(B, self).move() if it doesn’t have a path, and otherwise moves on the path. This is the proper way to override a method on a condition.

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

Sidebar

Related Questions

I have the following example code: class A(object): def __init__(self, id): self.myid = id
I have code like the following: class SomeSharedData(object): def __init__(self): self._lock = RLock() self._errors
I have two classes like the following: class Super(object): def __init__(self, arg): self.arg =
I have the following code: class IncidentTag: def __init__(self,tag): self.tag = tag def equals(self,obj):
consider the following code: class MyClass(object): def __init__(self): self.data_a = np.array(range(100)) self.data_b = np.array(range(100,200))
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }
Suppose I have the following code: class siteMS { ... function __CONSTRUCT() { require
I have the following code: public class Test { public static void Main() {

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.