zoukankan      html  css  js  c++  java
  • Python3:ImportError: No module named 'compiler.ast'

    from compiler.ast import flatten

    上面这条语句好像在python3 以后就废除了,如果使用的话就会报错。
    Traceback (most recent call last):
    File "eval_ssd_network.py", line 31, in <module>
    from compiler.ast import flatten
    ImportError: No module named 'compiler'

    或者
    Traceback (most recent call last):
    File "eval_ssd_network.py", line 31, in <module>
    from compiler.ast import flatten
    ImportError: No module named 'compiler.ast'

    因此,查资料显示,需要自己写一个函数:
    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"],[],[[]]]))


    参考文献
    [1].Python 3 replacement for deprecated compiler.ast flatten function.https://stackoverflow.com/questions/16176742/python-3-replacement-for-deprecated-compiler-ast-flatten-function
    [2].Python 3 replacement for deprecated compiler.ast flatten function. https://reformatcode.com/code/python/python-3-replacement-for-deprecated-compilerast-flatten-function

    ---------------------
    作者:农民小飞侠
    来源:CSDN
    原文:https://blog.csdn.net/w5688414/article/details/78489277
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    Cocos2d-x 2.2.3 Android配置
    于ubuntu配置hadoop当问题
    Xenomai 3 和 PREEMPT_RT 有哪些优势相比,
    【安卓注意事项】模仿猎豹清理大师波效应
    JPA实体继承映射
    第26周日许昌夜
    第26周六悲剧许昌夜
    第26黑色周五
    第26周四
    第26周三
  • 原文地址:https://www.cnblogs.com/jfdwd/p/11233302.html
Copyright © 2011-2022 走看看