I'm trying to make my first advanced python project but I'm struggling long time with imports.
Can someone describe me the usage of imports in python? Docs found about python imports in the official page is not so suffucient for me...
Here is an example:
I have the following source structure:
$ ls -ltrR
.:
total 1
drwx------+ 1 Administrators None 0 Nov 15 14:09 b
-rwx------+ 1 Administrators None 24 Nov 15 14:10 a.py
./b:
total 6
-rwx------+ 1 Administrators None 0 Nov 15 14:08 c.py
-rwx------+ 1 Administrators None 16 Nov 15 14:10 __init__.py
drwx------+ 1 Administrators None 0 Nov 15 14:10 __pycache__
-rwx------+ 1 Administrators None 61 Nov 15 14:10 b.py
and the content of the files:
$ cat a.py
import b
b.B().printC()
$ cat b/b.py
import c
class B:
def printC(self):
print(c.C().get())
$ cat b/c.py
class C():
def get(self):
return 'This is C'
$ cat __init__.py
from .b import *
When I start a.py it says: ImportError: No module named 'c'
.
When I start b.py only it says everything's fine.
Another solution when in b.py i'm modifying the import to "import b.c" -> in this case when I call a.py it will work, but when I call only b.py it is not going to work as b.py doesn't know b package.
Why do I need to start a.py and b.py also? a.py should be an executor for UTs, and b.py should be a UT. That's why it can happen that I would like to call all of the UTs and start a.py, and also it can happen that I'm just starting a specific UT (b.py).