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 Object-Oriented Python Dice Roller Giving a Hand

Begana Choi
PLUS
Begana Choi
Courses Plus Student 13,126 Points

How 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

boi
boi
14,242 Points

Try Google

Begana Choi
Begana Choi
Courses Plus Student 13,126 Points

Ok, 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
PLUS
Begana Choi
Courses Plus Student 13,126 Points

boi -_-... I tried to google it for 2hours now but it still isn't clear. how can you reply like this irresponsibly?? amazing

boi
boi
14,242 Points

I copy-pasted your title exactly as it is on google, The first search matched with your title.

👉 Stackoverflow

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
Begana Choi
Courses Plus Student 13,126 Points

boi the link doesn't match with my situation. and also, I googled my error .. still I haven't found a solution.

boi
boi
14,242 Points

What version of VSC do you have?

Begana Choi
Begana Choi
Courses Plus Student 13,126 Points

boi it's 1.51.1. I'm still looking for an answer - I think I almost found it. never mind...

boi
boi
14,242 Points

👍