9 lines
259 B
Python
9 lines
259 B
Python
#contextmgr1.py
|
|
with open("myfile.txt",'w') as f1:
|
|
f1.write("This is a sample file\n")
|
|
lines = ["This is a test data\n", "in two lines\n"]
|
|
f1.writelines(lines)
|
|
|
|
with open("myfile.txt",'r') as f2:
|
|
for line in f2.readlines():
|
|
print(line) |