[Python] ImportError: No module named html when using import html in Python [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I'm running into an issue trying to use the html module in Python. Here's the line that's causing the problem:

    import html


    When I run the script, I get this error:

    ImportError: No module named html


    I expected this to work since I saw html.escape() mentioned in a few examples online. I'm trying to escape some strings for safe HTML output (e.g., converting to <div>), but it fails at the import.

    A few details:

    I'm currently using Python 2.7 (yes, I know it's outdated — working with legacy code here).

    I've double-checked and I don't have any file named html.py in my working directory.

    Ideally, I want a solution that works with Python 2, but I'm open to hearing about how this would be handled in Python 3 as well.

    Is there a workaround or an alternative module I can use in Python 2 to achieve the same thing?

    Thanks in advance!

    Continue reading...

Compartilhe esta Página