[SciPy-user] maybe a bug in scipy.io.loadmat
xiaojf
FDU.xiaojf at gmail.com
Tue Sep 9 04:47:47 EDT 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',
**kwargs)
Load Matlab(tm) file
file_name - Name of the mat file
(do not need .mat extension if
appendmat==True)
If name not a full path name, search for the
file on
the sys.path list and use the first one found
(the
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
file_name.
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"
else:
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"
try:
fid = open(test_name,'rb')
fid.close()
full_name = test_name
break
except IOError:
pass
return full_name
More information about the SciPy-User
mailing list