Issue
I am trying to make a file that I can continuously add '../' to. My code is as follows:
with open("/tmp/newfile.txt", "a+") as myfile:
myfile.write('../')
contents = myfile.read()
print(contents)
However, when I run this code it returns <empty>
Solution
For Append File:
with open("newfile.txt", "a+") as file:
file.write("I am adding in more lines\n")
file.write("And more…")
For Read File:
with open('newfile.txt') as f:
lines = f.readlines()
print(lines)
Answered By - Kayes Fahim Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.