ModuleNotFoundError: No module named 'compiler'

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"],[],[[]]]))  

来源:https://blog.csdn.net/w5688414/article/details/78489277

posted @ 2021-09-26 08:34  ArdenWang  阅读(179)  评论(0编辑  收藏  举报