kjohansen
September 12th, 2008, 05:24 AM
Im confused on how importing libraries works.
I am trying to work with scipy
If I do
import scipy
print scipy.stats.mean([1,2,3,4]);
I get:
Traceback (most recent call last):
File "/home/johank/untitled-1.py", line 5, in <module>
print scipy.stats.mean([1,2,3,4]);
AttributeError: 'module' object has no attribute 'stats'
Process terminated with an exit code of 1
but if I do:
import scipy
import scipy.stats
print scipy.stats.mean([1,2,3,4]);
it works.
Why do I have to import scipy.stats as a separate line. I would expect that scipy.stats is a child and should be imported with scipy. I know I could do "from scipy import *", but I was warned against this by our friend pmasiar in a previous thread. Is this how it is supposed to be? Can I use one import to import the module and all its child modules?
I am trying to work with scipy
If I do
import scipy
print scipy.stats.mean([1,2,3,4]);
I get:
Traceback (most recent call last):
File "/home/johank/untitled-1.py", line 5, in <module>
print scipy.stats.mean([1,2,3,4]);
AttributeError: 'module' object has no attribute 'stats'
Process terminated with an exit code of 1
but if I do:
import scipy
import scipy.stats
print scipy.stats.mean([1,2,3,4]);
it works.
Why do I have to import scipy.stats as a separate line. I would expect that scipy.stats is a child and should be imported with scipy. I know I could do "from scipy import *", but I was warned against this by our friend pmasiar in a previous thread. Is this how it is supposed to be? Can I use one import to import the module and all its child modules?