我有一个文本文件,其中包含:
JavaScript 0
/AA 0
OpenAction 1
AcroForm 0
JBIG2Decode 0
RichMedia 0
Launch 0
Colors>2^24 0
uri 0
我写了这段代码来将文本文件转换为 html:
contents = open("C:\\Users\\Suleiman JK\\Desktop\\Static_hash\\test","r")
with open("suleiman.html", "w") as e:
for lines in contents.readlines():
e.write(lines + "<br>\n")
但我在 html 文件中遇到的问题是,在每一行中,两列之间没有空格:
JavaScript 0
/AA 0
OpenAction 1
AcroForm 0
JBIG2Decode 0
RichMedia 0
Launch 0
Colors>2^24 0
uri 0
我应该怎么做才能像文本文件中那样拥有相同的内容和两列
最佳答案
只需更改您的代码以包含 <pre>
和 </pre>
标签,以确保您的文本的格式与您在原始文本文件中设置的格式保持一致。
contents = open"C:\\Users\\Suleiman JK\\Desktop\\Static_hash\\test","r")
with open("suleiman.html", "w") as e:
for lines in contents.readlines():
e.write("<pre>" + lines + "</pre> <br>\n")
关于python - 使用python将文本文件转换为html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24715027/