I'm starting out with my very first python project but I'm running into a problem right from the start. I'm trying to figure out how to import a class into my main.py file.
My directory structure is...
game
- __init__.py
- main.py
- player.py
So far I have in main.py...
from player import Player
player1 = Player("Ben")
print player1.name
I get the following error...
Traceback (most recent call last): File "main.py", line 1, in from player import Player ImportError: cannot import name Player
I've had a google but can't find anything that works. Can someone help please?
I'm using Python 2.7.10
Update
So my player.py contains
class Player:
def __init__(self, name):
self.name = name
def name(self):
return self.name
and my init.py file is empty
player.py.__init__.pyandplayer.pyfor that matter.player.pyis not on thePYTHONPATHplayer.pyfile on your computer? It's possible that you're actually importing an older version ofplayerthat doesn't have aPlayerclass.