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"],[],[[]]]))  
原文地址:https://www.cnblogs.com/harbin-ho/p/12757532.html