[Tutor] "from X import Y" vs "import X"

emilia12 at mail.bg emilia12 at mail.bg
Wed Mar 21 12:24:02 CET 2007


Hi list,

In Python books one can read that "from X import Y" is
better than "import X", but some times (IMO) it is not.

for eg. in SciPy,

from numpy import matrix
from scipy.linalg import inv, det, eig
A=matrix([[1,1,1],[4,4,3],[7,8,5]])
print det(A)

crashes with :
RuntimeError: module compiled against version 1000002 of
C-API but this version of numpy is 1000009
RuntimeError: module compiled against version 1000002 of
C-API but this version of numpy is 1000009

BUT next code works fine:

from numpy import matrix
import numpy
A=matrix([[1,1,1],[4,4,3],[7,8,5]])
print numpy.linalg.det(A)

no crashes at all!

i am using: Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC
v.1310 32 bit (Intel)] on win32
and the last version of SciPy ...

my actual question is "is this a rare case related to the
scipy distribution, or something general in python"

regards,
e.












-----------------------------

SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
http://www.bgscena.com/



More information about the Tutor mailing list