我需要在网页上展示html的代码:
$ cat text.txt
<p><strong>Task:</strong><br>This is test text!</p>
$ cat output.txt but the answer is in the file output.txt He showed it to me like this:
<p><p><strong><strong>Task:</strong></strong><br>This is test text!</p><br></p>
如你所知,他出于某种原因重复不必要的标签:
<p><strong>, </strong><br>, </p>
我在守则中写出了什么错误?
我的方案守则如下:
$ cat main.py
#tag - теги html
#file - переменная файла
#fileread - считывание файла
#replacetags - замена тегов
#addtags - добавление тега p в файле
#tags=["<p>","</p>","<br>"," "]
tags=["<p>","</p>","<br>"," ","<strong>Task:</strong >"]
#print(tags[2])
with open("text.txt") as file:
fileread = file.read()
#print(fileread)
replacetags = fileread.replace(" ", tags[3]).replace("
", tags[2]).replace("Task:", tags[4])
#print(replacetags)
#print(tags[0], replacetags, tags[1])
addtags = tags[0]+replacetags+tags[1]
#print(addtags)
with open("output.txt", "w") as file:
file.write(addtags+"
")
这是我应当得到的答案,实际上:
<p><strong>Task:</strong><br>This is test text!</p>