Hey all! I am curious as to how the rest of the community imports their dependencies and why they choose to do it that way.
For instance, I generally find myself either bring in the library itself eg import pandas as pd
or a class within the library eg from requests import Session
. This has always worked for me, but I've heard others swear that you should only import the methods or functions you need for performance and/or security reasons.
So how do you bring in dependencies that you need and what is your reasoning behind doing it that way??
I'm not sure about "security reasons" (?) but there is a difference, albeit an insignificant one unless you are in a loop.
This is what happens at the moment of the import statement:
The only case where performance might actually matter is if you loop a lot of times and call a function inside another method. Taking from this answer - stackoverflow.com/a/33642848/4186181 - I ran the two example functions on Python 3.6.6 and I get these timings:
So yeah, if you're looping a lot consider aliasing the function