[SciPy-User] sugestion for loadmat (scipy.io)

Roel De Coninck roeldeconinck at gmail.com
Thu Sep 8 06:34:11 EDT 2011


Hi,

I spent a few hours trying to read some .mat files.  
The first error I got was a UnicodeDecodeError caused by 
VarReader4.read_char_array().  I could solve this by replacing 
S = arr.tostring().decode('ascii')
by
S = arr.tostring().decode('ascii', 'ignore')

Then, I got this error, caused by the same method read_char_array():
TypeError: buffer is too small for requested array 
(full error message see below)

I could solve this after trying lots of things, by changing 
S = arr.tostring().decode('ascii', 'ignore')
into
S = arr.tostring().decode('ascii', 'replace')

It also works with S = arr.tostring().decode('utf-8', 'replace'), which is 
maybe even better as ascii.

Is there a drawback to what I did that I did not yet discover? 
Else, I would suggest to add 'replace' to avoid UnicodeDecodeError in this 
method.

Kind regards,
Roel




More information about the SciPy-User mailing list