Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open('hello.txt', 'w+') as f:
- f.write('Hello world')
- f.seek(0)
- y = f.read()
- print y
- #with this format, the file will automatically close after the indent block. If you want to avoid #this, use the following format:
- x = open('hello.txt', 'w+')
- x.write('Hello world')
- x.seek(0)
- z = x.read()
- print z
- x.close()
- #I used w+ because I wanted to read and write from the same file without closing and reopening it. In #general, use 'a' to append (as opposed to writing over), 'r' to read, and 'w' to write.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement