[SciPy-dev] Small bug in miobase.py?

Jan Müller mueller@imt.uni-luebeck...
Thu Jul 9 14:41:45 CDT 2009


(Using 32 bit ubuntu, 0.70 scipy, python 2.6.2)

What happens:
---------
Accidentally I just tried to open an invalid matlab file using 

m = scipy.io.matlab.loadmat(...)

and got an unexpected error message. From the scipy source I was expecting an "Unknown mat file type..." message but all I got was a lousy unhandled TypeEror "not all arguments converted during string formatting"...


Steps to reproduce:
--------------
import scipy.io
filename = ... % an existing file which is _not_ a valid matlab file
ret = scipy.io.matlab.loadmat(filename)


Solution (?):
--------------
this is the relevant section:

def get_matfile_version(fileobj):
   % ...
   % do some stuff
   % ...
    if maj_val in (1, 2):
        return ret
    else:
        raise ValueError('Unknown mat file type, version %s' % ret)


If I change line 125 from 

raise ValueError('Unknown mat file type, version %s' % ret)

to

raise ValueError('Unknown mat file type, version %s' % str(ret))

everything works as expected.



Jan


More information about the Scipy-dev mailing list