Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Dice Roller Giving a Hand

Begana Choi
PLUS
Begana Choi
Courses Plus Student 13,124 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
8,836 Points

Try Google

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

What version of VSC do you have?

Begana Choi
Begana Choi
Courses Plus Student 13,124 Points

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

boi
boi
8,836 Points

👍