python read wreite code example
Example 1: python open and reacd file
with open('yourfile.txt','r') as f:
lines = f.readlines()
f.close()
Example 2: with open as file python
>>> with open('workfile') as f:
... read_data = f.read()
>>> # We can check that the file has been automatically closed.
>>> f.closed
True