I create a class Animal in a file animal.py
class Animal():
pass
I create a child class Dog in file dog.py
from animal import Animal
class Dog(Animal):
pass
If I run dog.py now, everything works.
Because these two classes are so incredibly useful, I now want to use them in my new project.
So I create a subfolder ./lib in my new project and copy the two files in here.
ProjectFolder:
- main.py
- lib/
- animal.py
- dog.py
Now want to use the Dog class in my main.py.
from lib.dog import Dog
sparky = Dog()
Aaand it doesn't work anymore because the Dog class can't find its Animal parent class. I guess because in sys.path[0] is now the path of main.py.
What is the correct approach here?
The two files animal.py and dog.py should of course work in every new project without having to adapt them every time.