ModuleNotFoundError: No module named 'compiler'

修改别人项目的时候出现的错误:ModuleNotFoundError: No module named 'compiler'

参考https://blog.csdn.net/w5688414/article/details/78489277已解决。

删除from compiler.ast import flatten

添加以下代码:

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"],[],[[]]]))  
posted @ 2020-04-22 22:52  ho_ho  阅读(1436)  评论(0编辑  收藏  举报