[SciPy-user] Re: io.loadmat
Prabhu Ramachandran
prabhu at aero.iitm.ernet.in
Wed Oct 15 04:40:53 EDT 2003
>>>>> "NW" == Nils Wagner <nwagner at mecha.uni-stuttgart.de> writes:
NW> I have used your setup script. However, I get into trouble
NW> from scipy import *
NW> import matfile
NM> load("matrizen_red.mat")
NW> #io.loadmat("matrizen_red.mat",appendmat=0)
NW> Traceback (most recent call last):
NW> File "matlab.py", line 3, in ?
NW> load("matrizen_red.mat")
NW> File
NW> "/usr/local/lib/python2.1/site-packages/Numeric/Numeric.py",
NW> line
NW> 506, in load
NW> return Unpickler(file).load()
NW> File "/usr/local/lib/python2.1/pickle.py", line 554, in
NW> __init__
NW> self.readline = file.readline
NW> AttributeError: readline
NW> Any suggestion ?
Well, sorry to sound rude but I think it helps if you learn to read
exceptions and interpret them if you are serious about using Python.
The above exception says that file.readline does not exist since you
called:
load("matrizen_red.mat")
If you look at the relevant lines quoted in the traceback, you will
immediately see that you invoked Numeric's load function (and not
matfile.load!). IIRC you ran into this problem a few days back and
Robert replied with the answer.
Now the exception goes on to say that Numeric's load is calling
pickle.py's __init__ member function and that function is trying to
find an attribute called readline in the file object you allegedly
passed.
Evidently, the object you passed has no readline method. A file
object in Python is supposed to have a readline method. Now you did
not pass a file object but a string which is not a file. So the thing
to do is to pass load() a file object.
load(open("matrizen_red.mat"))
will do the job.
My guess is that this is not what you want. Perhaps you wanted to do
matfile.load(...)?
In any case you might seriously want to consider reading the Python
tutorial if you are totally new to Python. The basics should take
less than an afternoon to read and you should be more comfortable with
all of the above.
cheers,
prabhu
More information about the SciPy-User
mailing list