converting text file to html file with python
html, python, text
Solution
Just change your code to include `<pre>` and `</pre>` tags to ensure that your text stays formatted the way you have formatted it in your original text file.
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")
Problem
I have a text file that contains : ``` JavaScript 0 /AA 0 OpenAction 1 AcroForm 0 JBIG2Decode 0 RichMedia 0 Launch 0 Colors>2^24 0 uri 0 ``` I wrote this code to convert the text file to 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") ``` but the problem that I had in html file that in each line there is no space between the two columns: ``` JavaScript 0 /AA 0 OpenAction 1 AcroForm 0 JBIG2Decode 0 RichMedia 0 Launch 0 Colors>2^24 0 uri 0 ``` what should I do to have the same content and the two columns like in text file