Reputation: 1371
I am making a small project in python. As part of this project, I created 7 functions. Each function is saved in a separate file. I also have a main file - the code inside of it runs the functions. each of the functions in the files needs at least two external libraries. Also, each external library is used at at least 2 functions.
Upvotes: 1
Views: 31
Reputation: 89527
where should I place the imports?
You place imports in each file that references that library. So if you have module 'A' and it has function my_func() that references 'math' you import it in the 'A' module.
if I call a function in a file that includes an import several times in the main code, will python redundantly import the library several times?
No, Python is smart enough to do it only once. It's kind of singleton. Before it load a module, Python will check if it's already loaded and if it's loaded, it will reuse it.
Upvotes: 1