[SciPy-user] maybe a bug in scipy.io.loadmat

xiaojf FDU.xiaojf@gmail....
Tue Sep 9 03:47:47 CDT 2008

Hi all,

I found that scipy.io.loadmat(filename) doesn't work when filename
contains '/' instead of '\\' as file path separater.

Help on function loadmat in module scipy.io.mio:

loadmat(file_name, mdict=None, appendmat=True, basename='raw',
    Load Matlab(tm) file

    file_name          - Name of the mat file
                         (do not need .mat extension if
                         If name not a full path name, search for the
file on
                         the sys.path list and use the first one found
                         current directory is searched first).
                         Can also pass open file-like object

The problem is in function find_mat_file, which tries to find the file
in directories listed in sys.path when there is no os.sep in

I couldn't understand why the function find_mat_file() tries to
find .mat file in directories listed in sys.path, since sys.path is
module search path not data file search path.

def find_mat_file(file_name, appendmat=True):
    ''' Try to find .mat file on system path

    file_name     - file name string
    append_mat    - If True, and file_name does not end in '.mat',
appends it
    if appendmat and file_name[-4:] == ".mat":
        file_name = file_name[:-4]
    if os.sep in file_name:
        full_name = file_name
        if appendmat:
            full_name = file_name + ".mat"
        full_name = None
        junk, file_name = os.path.split(file_name)
        for path in sys.path:
            test_name = os.path.join(path, file_name)
            if appendmat:
                test_name += ".mat"
                fid = open(test_name,'rb')
                full_name = test_name
            except IOError:
    return full_name

More information about the SciPy-user mailing list