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
版权声明:本文为博主原创文章,转载请附上博文链接!
Python3:ImportError: No module named 'compiler.ast'的更多相关文章
- ImportError: No module named 'commands'
/*********************************************************************** * ImportError: No module na ...
- python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'如何解决
python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'的解决方法: 1.原因是官网的是python2语法写的,看官手动把官 ...
- 关于python3.X 报"import urllib.request ImportError: No module named request"错误,解决办法
#encoding:UTF-8 import urllib.request url = "http://www.baidu.com" data = urllib.request.u ...
- python3 与 Django 连接数据库报错:ImportError: No module named 'MySQLdb'
在 python2 中,使用 pip install mysql-python 进行安装连接MySQL的库,使用时 import MySQLdb 进行使用 在 python3 中,改变了连接库,改为了 ...
- python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'如何解决【转载】
原文转自:http://bbs.chinaunix.net/thread-4154743-1-1.html python3中用HTMLTestRunner.py报ImportError: No mod ...
- python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'的解决方法:
全文转载至:http://www.cnblogs.com/testyao/p/5658200.html python3中用HTMLTestRunner.py报ImportError: No modul ...
- win7下python3.4 ImportError: No module named 'MySQLdb'错误解决方法
首先,安装PyMySQL C:\Users\fnngj>python -m pip install PyMySQL 执行以下命令会报错: ImportError: No module named ...
- ubuntu下使用python3的有些库时,解决"raise ImportError(str(msg) + ', please install the python3-tk package') ImportError: No module named '_tkinter', please install the python3-tk package"的错误
问题: 在Ubuntu下使用matplotlib这个库时,运行时出现如下错误: raise ImportError(str(msg) + ', please install the python3-t ...
- ImportError: No module named MySQLdb
ImportError: No module named MySQLdb 该错误是源于我们没有安装Python连接MySQL所需的MySQLdb库而引起. python3.5下的解决方法ubuntu系 ...
随机推荐
- JS方法大全
方法:document.createElement(tagName) 说明:创建指定元素 方法:document.createTextNode(文本) 说明:创建文本节点 方法:_dom.append ...
- 30分钟学webpack实战
阅读目录 一:什么是webpack? 他有什么优点? 二:如何安装和配置 三:理解webpack加载器 四:理解less-loader加载器的使用 五:理解babel-loader加载器的含义 六:了 ...
- node安装镜像和webpack
先安装node 安装指南:https://npm.taobao.org/
- jQuery的deferred对象使用详解【转载】
一.什么是deferred对象? 开发网站的过程中,我们经常遇到某些耗时很长的javascript操作.其中,既有异步的操作(比如ajax读取服务器数据),也有同步的操作(比如遍历一个大型数组),它们 ...
- CSS-DOM的小知识(二)
上篇文章说到,通过element.style.property可以获得元素的样式,但是style属性只能够返回内嵌样式,对于外部样式表的样式和head中的style样式都无法获取,这就限制了此方法的使 ...
- Django 的逆向解析url(转)
Django中提供了一个关于URL的映射的解决方案,你可以做两个方向的使用: 1.有客户端的浏览器发起一个url请求,Django根据URL解析,把url中的参数捕获,调用相应的试图, 获取相应的数据 ...
- console 中的格式化打印(占位符),和样式定义
格式化打印 Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6) 首次发布对string substitutions的支持.你可以在传递给 ...
- php表单和缩略图处理类是什么样呢
<?php//封装一个表单验证类//中文验证.邮箱验证.电话号码.手机.QQ.身份证.(由字母.数字.下划线组成,不能以数字开头)header('content-type:text/html;c ...
- 无线传感网络协议——Smart Mesh IP
前言: SmartMesh IP 专为实现 IP 兼容性而设计,并基于 6LoWPAN 和 802.15.4e 标准.SmartMesh IP 产品线实现了网络适应性.可靠性和可扩展性水平,并拥有高级 ...
- 各种高度的区别及height、clientHeight、scrollHeight、offsetHeight的区分
1.height.clientHeight.scrollHeight.offsetHeight 我们来实现test中的onclick事件 function justAtest() { ...