html
<form action="/result" method="post">
<label for="article">Post</label>
<input type="text" name="article">
<p></p>
<label for="name">name</label>
<input type="text" name="name">
<button type="submit">Send</button>
</form>
――This is the code that sends the input contents that you did last time
--Saved in ʻarticleandname` respectively
python
article = request.form["article"]
name = request.form["name"]
file = codecs.open("articles.txt", "a", "utf-8")
file.write(article + "," + name + "\n")
file.close()
--You can put this in any route
--ʻArticle = request.form ["article"] and name = request.form [" name"] are receiving the input and saved data as you did last time. --file = codecs.open ("articles.txt", "a", "utf-8") `` "a" is the mode to add --Declare to write with .write, separate with, with (article + "," + name + "\ n") , and write line by line by inserting \ n`
--The read mode to put in .open () is
--Read-only mode with
r--Write mode withw(this will completely overwrite and delete the previous data) -Mode added to the bottom with ʻa`
There is.
hoge.txt
foobarfoobar
When there is such a txt file,
python
open("hoge.txt","w").write(open("hoge.txt","r").read().replace("bar",""))
By
hoge.txt
foofoo
Can be done.
--This is because r refers to the contents of the txt file before writing with w.
――Honestly, I still don't understand much at the end
Recommended Posts