Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Context managers: with (file) experiments

with open('out.txt', 'w') as h:
    h.write("hello\n")

h = open('out.txt')
print(h.read())



f = open('out.txt', 'w')
f.write("hello\n")
f.close()

# for line in open("myfile.txt"):
#    print line,
# the file is closed only when script ends