简单demo
with open('d:/pydemo/pythonStart/fun1.py', 'r') as f:
#print(f.read())
while True:
line = f.readline()
#print(line)
if line == None or line == "" :
break;
# strip是去除行尾的
,不然print会输出一行
又空一行
print(line.strip())
文件读写模式
'r' open for reading (default)
'w' open for writing, truncating the file first
'x' open for exclusive creation, failing if the file already exists
'a' open for writing, appending to the end of the file if it exists
'b' binary mode
't' text mode (default)
'+' open a disk file for updating (reading and writing)
参考文章
python 文件读写
python官方文档