Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
722 views
in Technique[技术] by (71.8m points)

python - scipy.special import issue

I have an issue with importing the scipy.special package. It isn't harmful, just annoying/interesting.

When I import scipy using import scipy as sp and then try to access sp.special I get:

>>> import scipy as sp
>>> sp.special
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'special'
>>>

but if I then do import scipy.special I can access the special module through scipy.special and sp.special:

>>> import scipy as sp
>>> import scipy.special
>>> scipy.special
<module 'scipy.special' from 'C:Python27libsite-packagesscipyspecial\__init__.pyc'>
>>> sp.special
<module 'scipy.special' from 'C:Python27libsite-packagesscipyspecial\__init__.pyc'>
>>>

So I now have the special module accessible through both sp and scipy namespaces. The interesting bit is that I can access the rest of scipy through the scipy namespace.

First question: Why does the special module not import first time round?

Second question: How can I get access to the special module through the sp namespace only, without defining the scipy namespace?

Edit: using Python 2.7.2 and scipy 0.10.1

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By default, "import scipy" does not import any subpackage. There are too many subpackages with large Fortran extension modules that are slow to load. I do not recommend doing import scipy or the abbreviated import scipy as sp. It's just not very useful. Use from scipy import special, from scipy import linalg, etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...