hickle NameError:未定义名称'file'

时间:2018-01-16 07:39:41

标签: python python-3.x tensorflow

请向我解释为什么这个错误让我感到困惑。我在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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

作为hickle的主要开发者之一:3年前,它确实还不支持Python 3。 另一方面,现在它运行良好(事实上,现在已经放弃了对 Python 2.7 的支持)。