0

I am writing a chess program but don't quite understand inheritance. How can I use an attribute (empassant) from a parent class in a subclass? My parent class is:

class Pieces():
    def __init__(self, empassant=(-5,-5)):
        super().__init__()
        self.empassant=empassant

My subclass is:

class White (Pieces):

    def __init__(self):
        #stuff
    def pawn(self, pieceposition):
        empassant=#empassant from the pieces class
1
  • If you search in your browser for "Python class inherit tutorial", you'll find references that can explain this much better than we can manage here. Commented Oct 10, 2019 at 0:36

1 Answer 1

1

you need to call super().__init__() first in the __init__ of the child

class White (Pieces):

    def __init__(self):
        super().__init__()
        #others initialization here

    def pawn(self, pieceposition):
        print(self.empassant)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.