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 trial

Python

When returning self.get_weapon(), why do we not return get_weapon(self) instead?

2 Questions:

  • Why is it that we do not return get_weapon(self), where self is the 1 argument for get_weapon
  • And why is it that the error we get is a "not defined" error even though we've defined it a few lines above?

Sample code: ```File "/Users/xxxxx/Desktop/code/python/character.py", line 22, in init self.weapon = self.get_weapon() File "/Users/xxxxx/Desktop/code/python/character.py", line 17, in get_weapon return get_weapon() NameError: name 'get_weapon' is not defined

1 Answer

Hello Mark.

First question: The get_weapon is a method of the class (if I remember correctly), so to call it, the normal procedure is the one that the teacher shows in the video. get_weapon(self) I would presume would be a function call (speaking in general, not relative to this case in particular).

The second question is a bit more complicated I think, and I think you should paste the relative piece of code so that we can have a look at it.

Thanks

Vittorio