Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python h5py IOError:无法打开文件_Python_H5py_Ioerror - Fatal编程技术网

Python h5py IOError:无法打开文件

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

出于某种奇怪的原因,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/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')