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 trialClayton McDaniels
5,788 PointsCan't import the card class.
class Card:
def __init__(self, word, location):
self.card = word
self.location = location
self.matched = False
def __eq__(self, other):
return self.card == other.card
def __str__(self):
return self.card
if __name__== "__main__":
card1 = Card("egg", "A1")
card2 = Card("egg", "B1")
card3 = Card("hut", "D4")
When I run "from cards import Card" I get an import error. My file is named "cards.py".
1 Answer
Clayton McDaniels
5,788 PointsI actually solved it, by using your clue to the path. It was an editor issue with Visual Studio Code. I created a new workspace and folder(project) and dropped cards.py and games.py into the new folder(project). I was able to run the code cleanly in the terminal, after that.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsCan you say more about how your are attempting to import from this file?
This file looks and executed cleanly. The issue seems to be on the actual import. Can you confirm you are in the same directory, then try importing in the REPL?