#-*-coding:utf-8-*-
#kang liang
#https://zhuanlan.zhihu.com/p/42784651
#https://www.cnblogs.com/mghhzAnne/p/10282964.html
#https://www.runoob.com/python/python-files-io.html
import os
#method 1:str, speed
with open(os.getcwd()+'/test.txt','r') as f:
	for line in f:
		print(line)
#method2: read() tuple
with open(os.getcwd()+'/test.txt','r') as f:
	ff=f.read()
	print(ff)
#method3: readlines():lines are list, line is str
with open(os.getcwd()+'/test.txt','r') as f:
	lines=f.readlines()
	for line in lines:
		print(line)
#method4: readline(): line by line, save memory
with open(os.getcwd()+'/test.txt','r+') as f:
	line=f.readline()
	while line:
		print(line)
		line=f.readline()
#write: readline(): line by line, save memory
with open(os.getcwd()+'/test.txt','a') as f:
	f.write("Hello world!\n")
with open(os.getcwd()+'/test.txt','r+') as f:
	line=f.readline()
	while line:
		print(line)
		line=f.readline()