1

Ive made these classes below and I'm trying to have a tile in the game present a text based on an attribute in another class. I keep getting this error. File "C:\Users\xxxxxxxx\PycharmProjects\Game.idea\Girls.py", line 20, in not_interested return (self.interest < 10) AttributeError: 'GirlTile' object has no attribute 'interest'

class Girls():
    def __init__(self):
        self.girlnames = ["Lucy", "Cindy", "April", "Allison", "Heather", "Andrea", "Brittany", "Jessica", "Lane", "Lauren", "Sabrina","Chelsea","Amber"]
        self.name = random.choice(self.girlnames)
        self.height = random.randrange(60, 72)
        self.age = random.randrange(18, 25)
        self.number = self.new_number()
        self.interest = 0

        def not_interested(self):
            return (self.interest < 10)

from Girls import Girls

class GirlTile(MapTile):
    def __init__(self,x,y):
        self.enemy = Girls()
        super().__init__(x, y)

    def intro_text(self):
        self.stance = Girls.not_interested(self)
        if self.stance:
            print("Hey whats up")
3
  • GirlTile class is not the same as the Girls class, only Girls have interest. You are passing an instance of GirlTile to Girls.not_interested() - I assume you meant self.enemy.not_interested(). Commented Nov 24, 2016 at 2:25
  • Just updated it to show the line Commented Nov 24, 2016 at 2:27
  • You need an instance of Girls, if self.enemy is not the correct instance then presumably you need an argument to intro_text(self, girl). Commented Nov 24, 2016 at 2:29

1 Answer 1

1

It looks like not_interested is an instance-level method, but you are trying to call it with a class (Girls). And the call is sort of "working" because you are passing the GirlTile instance in the call -- hence the error that the GirlTile has no interest attribute (because it does not).

Maybe you intended this instead?

def intro_text(self):
    # Use an actual Girl instance to call not_interested().
    self.stance = self.enemy.not_interested()
    ...
Sign up to request clarification or add additional context in comments.

1 Comment

ahhhhh yes that makes perfect sense! Much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.