This is pretty much Python, but asking from a Django user.
Suppose this is how Django apps are layout:
Webclient
- apps
- myapp#1
- library
- library.py
- myapp#2
- views.py
- myapp#3
If I am working with views.py, and I want to import library.py, which one seems better?
from webclient.apps.myapp.library import LibraryClass
from webclient.apps.myapp.library.library import LibraryClass
I am using PyCharm, and either way doesn’t complain about “unresolved references”.
Is it better to import very speifically. Is second import method more likely to avoid name collison, if possible at all (say /library/ has several .py files)?
Thanks.
You should always import names from where they’re defined. That way if
webclient.apps.myapp.libraryshould stop importingLibraryClassone day, you won’t break the other imports.