关于 train2.pkl 中from compiler.ast import flatten的问题
YuQuankun opened this issue · 1 comments
YuQuankun commented
报错信息为:
Traceback (most recent call last):
File "train2pkl.py", line 94, in
from compiler.ast import flatten
ImportError: No module named 'compiler.ast'
网上查阅资料说是因为在python3以后这段话就被废除了,请问如何解决呢?
jkx1206 commented
用下面函数替换就行
import collections
def flatten(x):
result = []
for el in x:
if isinstance(x, collections.Iterable) and not isinstance(el, str):
result.extend(flatten(el))
else:
result.append(el)
return result