1

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>

DuckHunt
  • 68
  • 1
  • 11

1 Answers1

2

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)
Kayes Fahim
  • 672
  • 5
  • 16