Imports slower python scripts?

Just wondering if it imports more functions from other scripts, slowing down the script at all?

Some background:

I have two scenarios, one of which works much faster than the other, it has an additional import statement at the top and an additional function at the bottom, but its contents in the middle, the same thing between scripts that work slower,

+4
source share
1 answer

More on your case, Import_Statement_Overhead :

Import statements can be executed anywhere. It is often useful to place them inside functions in order to limit their visibility and / or reduce the initial launch time. Although the Python interpreter is optimized so as not to import the same module multiple times, repeatedly executing the import statement can seriously affect performance in some cases .

+6
source

Source: https://habr.com/ru/post/1499107/


All Articles