Answer the question
In order to leave comments, you need to log in
What is the best way to use python libraries in multiple code files?
I have libraries, I have code on several files: is it better to store imports in one file and call this file in each code file? I just don't know how to make it more convenient, because some libraries are needed in one file, others in another
Answer the question
In order to leave comments, you need to log in
Import as usual, in each file.
A generic file with imports will only complicate matters, but will not give any gain in code readability, since different files will require different modules.
I also advise you to follow the PEP8 standard in terms of the order of imports:
First imports of standard modules.
Then imports of third-party libraries (what I installed via pip).
Last but not least, module imports from your project.
Within each section, the elements can be ordered alphabetically, unless there is a particular reason to import them in a different order.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question