Answer the question
In order to leave comments, you need to log in
Are all dependent libraries used when imported into Python?
Now I am writing my own library for Python, which will be compatible with Django/SQLAlchemy ORM. At the moment, the structure inside the library/package is as follows:
MyProject
|-- db
|-- orm
|-- django
|-- sqlalchemy
Answer the question
In order to leave comments, you need to log in
In Python, imports are completely dynamic and happen at runtime. You can write:
if moon_phase == 42:
import sqlalchemy
ImportError
it will fly out at a certain phase of the moon. mylibrary_core
.mylibrary_django
, for example).django
, for example).mylibrary_django
, which automatically pulls up mylibrary_core
, which the user does not have to worry about.is_user_install_anything_useful = False
try:
import django
is_user_install_anything_useful = True
except ImportError:
pass
try:
import sqlalchemy
is_user_install_anything_useful = True
except ImportError:
pass
if not is_user_import_anything_useful:
raise ImportError('Install django or SQLalchemy')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question