Skip to main content
 首页 » 编程设计

python之hickle 名称错误 : name 'file' is not defined

2024年09月07日11zengkefu

请向我解释为什么会出现此错误。我已经在 ubuntu 中安装了 python 3.5

import os 
import hickle as hkl 
import numpy as np 
array_obj = np.ones(32768, dtype='float32') 
hkl.dump(array_obj, 'test.hkl', mode='w')

结果是

Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35\lib\site-packages\hickle.py", line 308, in dump 
    h5f = file_opener(file_obj, mode, track_times) 
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35\lib\site-packages\hickle.py", line 148, in file_opener 
    if isinstance(f, file): 
NameError: name 'file' is not defined

请您参考如下方法:

Hickle 不支持 Python3(它使用 Python3 不支持的 file() 函数),但你可以找到 modified version在 GitHub 上,或者只使用 Python2。