with open('file.txt', 'r') as out_file: print(out_file.write('hello'))That way you don't have to use close() after opening the file. It closes automaticaly. The with statement is called context manager.
Writing to a file:
with open('file.txt', 'w') as in_file: in_file.write('hello')