Generating HTML documents in python

前端 未结 7 1198
花落未央
花落未央 2020-11-28 03:43

In python, what is the most elegant way to generate HTML documents. I currently manually append all of the tags to a giant string, and write that to a file. Is there a mor

7条回答
  •  天命终不由人
    2020-11-28 04:26

    Yes, you are looking for file .writelines

    A sequence is generally a list or array. So put all your lines into a list or array. And toss them to the function below.

    Make sure to remove any new line constants from your strings just to be safe

    Python Documentation ( search for file.writelines )

    file.writelines(sequence) Write a sequence of strings to the file. The sequence can be any iterable object producing strings, typically a list of strings. There is no return value. (The name is intended to match readlines(); writelines() does not add line separators.)

提交回复
热议问题