Typically, one uses import numpy as np to import the module numpy.
Are there general conventions for naming?
What about other modules, in particular from scientific computing like scipy, sympy and pylab or submodules like scipy.sparse.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SciPy recommends
import scipy as spin its documentation, though personally I find that rather useless since it only gives you access to re-exported NumPy functionality, not anything that SciPy adds to that. I find myself doingimport scipy.sparse as spmuch more often, but then I use that module heavily. AlsoYou might encounter more of these as you start using more libraries. There’s no registry or anything for these shorthands and you’re free to invent new ones as you see fit. There’s also no general convention except that
import lln as library_with_a_long_nameobviously won’t occur very often.Aside from these shorthands, there’s a habit among Python 2.x programmers to do things like
Python 3.x is putting an end to this, though, because it no longer offers partial C implementations of
StringIO,pickle, etc.