from compiler.ast import flatten
提示:
Traceback (most recent call last):
File "eval_ssd_network.py", line 31, in <module>
from compiler.ast import flatten
ImportError: No module named 'compiler'
查资料显示,需要自己写一个函数:
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
print(flatten(["junk",["nested stuff"],[],[[]]]))