How to write and save html file in python?

前端 未结 6 2334
挽巷
挽巷 2020-12-05 02:22

This is what I know how to write and save it

Html_file= open\"(filename\",\"w\")
Html_file.write()
Html_file.close

But how do I save to the

6条回答
  •  清歌不尽
    2020-12-05 03:04

    You can create multi-line strings by enclosing them in triple quotes. So you can store your HTML in a string and pass that string to write():

    html_str = """
    
         <% for i in range(10): %>
           
    Number Square
    <%= i %> <%= i**2 %>
    """ Html_file= open("filename","w") Html_file.write(html_str) Html_file.close()

提交回复
热议问题