Issue
how to save/copy text from text file to html file, without or with formatting to leave the text unchanged.
Example:
> ❯ cat TEST.txt
TEST TEST 1 ONE TEST
234 TEST AGAIN TEST
1234 : : : TEST TEST%
Code:
with open('TEST.txt', 'r') as firstfile, open('RESULT.txt', 'a') as secondfile:
# read content from first file
for line in firstfile:
# append content to second file
secondfile.write(line)
Result:
❯ cat RESULT.txt
TEST TEST 1 ONE TEST
234 TEST AGAIN TEST
1234 : : : TEST TEST%
Now it worked well but when I try to save second file as HTML it has different result where all strings copied in one.
Code:
with open('TEST.txt', 'r') as firstfile, open('RESULT.html', 'a') as secondfile:
# read content from first file
for line in firstfile:
# append content to second file
secondfile.write(line)
Result:
TEST TEST 1 ONE TEST 234 TEST AGAIN TEST 1234 : : : TEST TEST
But I need to copy strings unchanged from txt file to html file.
thank you.
Solution
Use html to create new line
with open('TEST.txt', 'r') as firstfile, open('RESULT.html', 'a') as secondfile:
# read content from first file
for line in firstfile:
# append content to second file
secondfile.write(line + '<br/>')
Answered By - Rizquuula
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.