[Python] How to store a html file in a variable as a string in python

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have html file and I want to store the contents of that file in a variable as a string value. I have tried this but it returns a blank string. How can I do this?

    def myfunc():
    str = ""
    with open("/home/suman/Alert_logo_report.html") as report_file:
    raw_html = report_file.readlines()
    str = ''.join(raw_html)
    return str

    Continue reading...

Compartilhe esta Página