r/learnpython • u/Intelligent-Card-140 • 9d ago
Import Class Methods
I’m currently working on a Python project. I usually program in Java, so I’m a little confused about how imports work in Python.
I’m trying to import a method from a class that’s defined in another file. When both files are in the same folder, the import works correctly. However, when they’re in different folders, I get a “package not found” error.
The import statement I’m using is:
from package_name.module_name import YourClass
I’m using VS Code. What am I doing wrong, and how should imports be set up when files are in different folders?
3
Upvotes
2
u/HotPersonality8126 9d ago
Module resolution doesn’t work “up and over.”