我在一个类中命名了元组。使用 dill 进行酸洗时,它会抱怨无法在顶部模块中找到 namedtuple 对象的经典问题。
import dill as pickle
class NNRTMParse(object):
def __init__(self,logfile)):
.
.
.
.
self.TM = namedtuple('TM',tmeas_fields)
#print self.TM
CFH = namedtuple('CFH',cfhdr_fields)
PM = namedtuple('PM',pmeas_fields2)
print PM
这是 self.TM 和其他人的默认分配,我在解析日志时动态分配 namedtuple。
但是酸洗:
if __name__ == "__main__":
filename = 'dbggen_rx_loc_2-llh_rtm_lla_out_20160929_130711_day2_4381_JN2_SN64_rtmproc_2M5M.txt'
N = NNRTMParse(filename)
N.parse()
N.get_rx_loc('oak484_bora-llh')
filehandler = open("NNRTMParse_JB2-SN052.obj","wb")
pickle.dump(N,filehandler)
filehandler.close()
Traceback (most recent call last):
File "C:/NN_Hardware/spos_proc/NNRTMParse.py", line 937, in <module>
pickle.dump(N,filehandler)
File "C:\Python27\lib\site-packages\dill\dill.py", line 236, in dump
pik.dump(obj)
File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\site-packages\dill\dill.py", line 835, in save_module_dict
StockPickler.save_dict(pickler, obj)
File "C:\Python27\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python27\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\site-packages\dill\dill.py", line 1189, in save_type
StockPickler.save_global(pickler, obj)
File "C:\Python27\lib\pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <class '__main__.TM'>: it's not found as __main__.TM
我不确定是否有任何出路。否则将不得不通过路径来挑选要腌制的数据帧,我讨厌这样做。
非常感谢任何帮助。