We have some code that takes great pains to import code one function at a time. Other code imports lots of functions from the same module, but lists each function that is used in the module. Other code just imports the package name and uses it when needed to call a function from that package.
from numpy import min
from numpy import max
from numpy import abs
x = min(abs(max(y)))
VS
from numpy import min, max, abs
x = min(abs(max(y)))
VS
import numpy as np
x = np.min(np.abs(np.max(y)))
Recently, I was trying to figure out where a package (numpy) was being used in a module. It would have been quite easy if the 3rd style was used.... I just search for "np." in my editor. With either of the first two styles I have to search for min and max and abs and those words appear much more frequently (in comments and in docs as well as code) and I have to check whether the function has been defined as a local variable inside the function before being called (unlikely with this example min/max/abs, but i worried about it anyway).
Between the first two styles, I prefer the second because the code is more compact. And we used to always do it that way, but about 6 years ago people started using the more verbose style and even changing imports to that style.
Is there a Style guide preference for imports that anyone knows about? Or even a blog post by people who've thought about it some? I think we should work toward making ours more uniform.
We have some code that takes great pains to import code one function at a time. Other code imports lots of functions from the same module, but lists each function that is used in the module. Other code just imports the package name and uses it when needed to call a function from that package.
VS
VS
Recently, I was trying to figure out where a package (numpy) was being used in a module. It would have been quite easy if the 3rd style was used.... I just search for "np." in my editor. With either of the first two styles I have to search for min and max and abs and those words appear much more frequently (in comments and in docs as well as code) and I have to check whether the function has been defined as a local variable inside the function before being called (unlikely with this example min/max/abs, but i worried about it anyway).
Between the first two styles, I prefer the second because the code is more compact. And we used to always do it that way, but about 6 years ago people started using the more verbose style and even changing imports to that style.
Is there a Style guide preference for imports that anyone knows about? Or even a blog post by people who've thought about it some? I think we should work toward making ours more uniform.