在调试Hin2vec的时候,出现了TypeError: a bytes-like object is required, not ‘str’,源代码为2.7,我改成3.5运行之后就报错了。
在python3中需要加入encoding=’bytes’,而python2中不需要。
1.报错如下
TypeError: a bytes-like object is required, not ‘str’
2.源代码
def load_a_HIN_from_pickle_file(fname):
'''
Load a HIN from a pickled file
The pickled file can be generated by tools/pickle_a_HIN.py
'''
g = pickle.load(open(fname))
# 输出class_,count,edg_class2id
g.print_statistics()
return g
3.修改之后的代码
def load_a_HIN_from_pickle_file(fname):
'''
Load a HIN from a pickled file
The pickled file can be generated by tools/pickle_a_HIN.py
'''
g = pickle.load(open(fname, 'rb'), encoding='bytes')
# 输出class_,count,edg_class2id
g.print_statistics()
return g
4.成功解决
References
https://blog.csdn.net/qq_37118044/article/details/83151353