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 trialBegana Choi
Courses Plus Student 13,126 PointsHow to import a class to another python file? (using Visual Studio Code)
I'm trying to write the code outside of the workspace.
I'm using Visual Studio Code
and I can't use from [filename] import [class_name]
please help me !!
there are 2 files that dice.py
and hands.py
in dice
directory.
and I want to retrieve D6 class
to hands.py.
+) so I made __init__.py
file in the same directory (in dice
directory) and tried to retrieve them
e.x.) from .dice import D6
and I get error : ImportError: attempted relative import with no known parent package
Begana Choi
Courses Plus Student 13,126 PointsOk, I've found out the problem.. it was a bug - I've just rebooted my laptop and it works very well...
even I didn't need to make a __init__.py
file. it happened a few times to me.
but thank you for trying to help me boi
1 Answer
Begana Choi
Courses Plus Student 13,126 Pointsboi -_-... I tried to google it for 2hours now but it still isn't clear. how can you reply like this irresponsibly?? amazing
boi
14,242 PointsI copy-pasted your title exactly as it is on google, The first search matched with your title.
My reply wasn't an answer, it was a comment, there is a difference. And I wasn't trying to be irresponsible but gave a suggestion.
Begana Choi
Courses Plus Student 13,126 Pointsboi the link doesn't match with my situation. and also, I googled my error .. still I haven't found a solution.
boi
14,242 PointsWhat version of VSC do you have?
Begana Choi
Courses Plus Student 13,126 Pointsboi it's 1.51.1. I'm still looking for an answer - I think I almost found it. never mind...
boi
14,242 Pointsboi
14,242 PointsTry Google