Best practices regarding partial import of hand-selected functions into global namespace

[email protected] Tue, 22 Mar 2022 05:22:29 -0000
Newsgroups gmane.comp.python.scientific.user
Message-ID <[email protected]>
Hi all,

I have a question regarding best practices for imports when using scipy. I understand that doing things like `from numpy import *` is discouraged and that it is best to keep the global namespace clean. On the other hand, it can also be useful to hand-select some functions from numpy or scipy and import them into the global namespace. Virtually all of the scipy examples use this code style. For instance from https://docs.scipy.org/doc/scipy/reference/sparse.html (combining some things for brevity):

```
from scipy.sparse import csr_matrix
from scipy.sparse import lil_matrix
from scipy.sparse.linalg import spsolve
from numpy.linalg import solve, norm
...
```

etc. Is this considered acceptable practice, then, as long as you aren't shadowing built-ins and the like? I ask because for any reasonable program you will of course never just use three or four functions, but as you keep developing will quickly get to 20-30 or 50 or more. Is that alright then?

Are there any guidelines or best practices regarding this usage, particularly if you have a package with several submodules and etc?
_______________________________________________
SciPy-User mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/scipy-user.python.org/
Member address: [email protected]