python - 无法从 'html' 导入名称 'HTML' 。Python 3.7.4
问题描述
我正在使用 Python 3.7.4 只是尝试运行此代码:
from html import HTML
table_data = [
['Last name', 'First name', 'Age'],
['Smith', 'John', 30],
['Carpenter', 'Jack', 47],
['Johnson', 'Paul', 62],
]
htmlcode = HTML.table(table_data)
print (htmlcode)
但收到此错误:
Traceback (most recent call last):
File "c:\UserName\Documents\Programming Learning\PythonLearning\Sending HTML Email\tempCodeRunnerFile.py", line 1, in <module>
from html import HTML
ImportError: cannot import name 'HTML' from 'html' (C:\Users\username\AppData\Local\Programs\Python\Python37\lib\html\__init__.py)
还有其他获取 HTML 模块的方法吗?
解决方案
尝试 python 2.7
└─╼ python2.7
Python 2.7.15 |Anaconda custom (64-bit)| (default, May 1 2018, 18:37:05)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from html import HTML
>>>
>>> quit()
python3有html.entities.html5和html._html5,都不能满足你的目的
推荐阅读
- php - 为什么我的 .htaccess 设置不适用于 $_GET?
- windows - 更改文件名中的某个字符串(Windows 批处理循环,通配符)
- functional-programming - keras 中的一维卷积序列
- javascript - 如何在“ios contenteditable element”中格式化文本后恢复平滑滚动?
- r - 匹配 R 中数据框列表中的日期
- mysql - 是否存在诸如“过度索引”数据库表之类的事情?
- html - 访问 React Router 历史堆栈
- javascript - “请求的资源上不存在 'Access-Control-Allow-Origin' 标头”(未捕获的 SyntaxError:意外的标识符)
- c - 用 GLib 替换文本
- ruby-on-rails - 如何在每个循环中从连接模型对象中删除对象