首页 > 解决方案 > 无法从 '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 模块的方法吗?

标签: pythonpython-3.xpandas

解决方案


尝试 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,都不能满足你的目的


推荐阅读