【问题标题】:h5py IOError: unable to open fileh5py IOError:无法打开文件
【发布时间】:2019-01-22 19:03:42
【问题描述】:

由于某种奇怪的原因,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”……但为什么呢?任何帮助表示赞赏。

【问题讨论】:

  • 试试r"你的路径"
  • 谢谢丹奇。但它与文字字符串无关......不起作用。

标签: python h5py ioerror


【解决方案1】:

如果你想使用 ~/ 路径,使用 os.path.expanduser()

import os

your_path=os.path.expanduser('~/Dropbox/premalstuff/r/data/daily-mrgshrgpd.h5')
infile = h5py.File(your_path,'r')

或者使用绝对路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-26
    • 2017-10-05
    • 2014-12-24
    • 1970-01-01
    • 2015-07-03
    相关资源
    最近更新 更多