text = 'writing a text\nhello world'
my_file = open('file.txt','w')
my_file.write(text)
my_file.close()
with open('file.txt','w') as f:
f.write('11111\n22222')
with open('file.txt','a') as f:
f.write('11111\n22222')
with open('file.txt','r') as f:
content = f.read()
print(content)
with open('file.txt','r') as f:
content = f.readline()
print(content)
with open('file.txt','r') as f:
content = f.readlines()
print(content)
filename = 'file2.txt'
with open(filename) as f:
for line in f:
print(line.rstrip())