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 trialJeremy Bradrick
6,731 PointsIronPython 2.7 errors out while Workspaces and PyCharm both work
I'm following along with the video using IronPython 2.7. When I try to create the character in the IronPython console, I get the following error:
>>> from character import Character
>>> player = Character()
Name: Jeremy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\IronPython 2.7\character.py", line 17, in __init__
NameError: name 'Jeremy' is not defined
>>> player = Character()
Name: jeremy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\IronPython 2.7\character.py", line 17, in __init__
NameError: name 'jeremy' is not defined
When I run it in PyCharm or workspaces it works fine. Here is the code:
class Character:
experience = 0
hit_points = 10
def get_weapon(self):
weapon_choice = input("Weapon ([S]word, [A]xe, [B]ow): ").lower()
if weapon_choice in 'sab':
if weapon_choice == 's':
return 'sword'
elif weapon_choice == 'a':
return 'axe'
else:
return self.get_weapon()
def __init__(self, **kwargs):
self.name = input("Name: ")
self.weapon = self.get_weapon()
for key, value in kwargs.items():
setattr(self, key, value)
Does this have to do with the version of Python?
1 Answer
Ullas Savkoor
6,028 Pointshave you tried by making your class inherit from object?
class Character(Object)