Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGarrett Phipps
Courses Plus Student 2,808 PointsBound method elsewhere?
I'm 99% certain that I did everything the same as in the video, but every time I check the battlecry of a new class I'm told that it's been bound elsewhere. I have no idea what that means or how to handle it. Would someone please explain what it is, how it happens, and how to deal with it? Here's the bits and pieces:
file:
class Monster:
def __init__(self, **kwargs):
self.hitpoints = kwargs.get('hitpoints', 1)
self.weapon = kwargs.get('weapon', 'sword')
self.color = kwargs.get('color', 'blue')
self.sound = kwargs.get('sound', 'roar')
def battlecry(self):
return self.sound.upper()
shell:
input position
output position
from monster import Monster
Eagle=Monster(weapon='beak',sound='tweet')
Eagle.weapon
'beak'
Eagle.battlecry
<bound method Monster.battlecry of <monster.Monster object at 0x7fee4bd39080>>
Eagle.sound
'tweet'
1 Answer
Alexander Davison
65,469 PointsYour code in the file is 100% fine, but the code in your shell is wrong.
However, you aren't calling the function battlecry
in the Shell. You are just trying to retrieve the location of the function in memory, that's why you get this "scary-looking" ID.
Add parens to the end to tell Python to call the function and you should be good! The code to call the function is below:
Eagle.battlecry()
Also, just FYI, it's bad practice to use an uppercase letter in the name Eagle
since it's not a class but it's a plain old variable assigned to a instance of the Monster
class. The only time you capitalize the first letter of a name in Python is when you make the name of the class. Remember: Eagle
is not a class, therefore should be capitalized, but Monster
is! This means that eagle
is a better name then Eagle
but Monster
is fine
Juts for your information
I hope this helps
~Alex
Garrett Phipps
Courses Plus Student 2,808 PointsGarrett Phipps
Courses Plus Student 2,808 PointsOh, geez lol! Thanks!