Python h5py IOError:无法打开文件
出于某种奇怪的原因,h5py无法找到输入文件。除非输入文件与试图打开该文件的模块位于同一目录中,否则它会始终抛出此错误。这很奇怪,因为它在不久前工作得很好:Python h5py IOError:无法打开文件,python,h5py,ioerror,Python,H5py,Ioerror,出于某种奇怪的原因,h5py无法找到输入文件。除非输入文件与试图打开该文件的模块位于同一目录中,否则它会始终抛出此错误。这很奇怪,因为它在不久前工作得很好: infile = h5py.File("~/Dropbox/premalstuff/r/data/daily-mrgshrgpd.h5",'r') 以及IOError的摘录: IOError: Unable to open file (Unable to open file: name = '~/dropbox/premalstuff/r
infile = h5py.File("~/Dropbox/premalstuff/r/data/daily-mrgshrgpd.h5",'r')
以及IOError的摘录:
IOError: Unable to open file (Unable to open file: name = '~/dropbox/premalstuff/r/data/daily-mrgshrgpd.h5', errno = 2, error message = 'no such file or directory', flags = 0, o_flags = 0)
相关目录中的目录列表:
我看到h5py将“Dropbox”改为“Dropbox”…但为什么?非常感谢您的帮助。如果您想使用~/path,请使用os.path.expanduser()
或者使用绝对路径。试试“你的路径”谢谢danche。但它与文本字符串无关…不起作用。
import os
your_path=os.path.expanduser('~/Dropbox/premalstuff/r/data/daily-mrgshrgpd.h5')
infile = h5py.File(your_path,'r')