The following test shows Python interprets A
as dir.a.A
. How can I make Python interprets A
as dir.A
?
$ find * -name "*.py"
dir/a.py
dir/__init__.py
main.py
$ cat dir/a.py
class A():
pass
$ cat dir/__init__.py
from .a import A
$ cat main.py
from dir import A
print(A)
$ python3 main.py
<class 'dir.a.A'>
I know the following can yield the result I want, but I want to achieve it without changing the directory/file structure.
$ ls
dir.py main.py
$ cat dir.py
class A():
pass
$ cat main.py
from dir import A
print(A)
$ python3 main.py
<class 'dir.A'>
Or, shouldn't I care about this? (I'm a newbie to Python.)