2

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>

3

1 Answer 1

4

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) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.