0
r+ in python
with open("test2.txt", "r+") as myfile: m = myfile.write("ssss") print(myfile.read()) output = Why does this output appear ?As it should be: ssss
6 Respostas
+ 3
put:
myfile.seek(0)
Above print(myfile.read())
+ 1
Slick
Thank you❤️
It worked
+ 1
The tests ive run it seems like it does overwrite the file. If you dont want to overwrite, you can always create a blank file, then in python:
myfile = open('filepath', 'a+')
This will append any data written to the file after
+ 1
Not any way that i know of. I usually use it like
file.seek(0) to go the the begging and
file.seek(2) to go to the end.
you can do something sort of like mad libs though. If you already know the majority of whats going into a file, you can format a variable into whatever you want to write in your file.
dinner = input('What would you like for dinner? ')
msg = f'I sure would love {dinner} tonight. It's my favorite!'
file = open('filepath', 'a')
file.write(msg)
Thats the best ive got
0
Slick
Does the r+ overwrite the file
0
Slick
Can I seek this to write in the middle of the file?