Python3 读写文件
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#读文件
#with open('C:/Users/Administrator/Desktop/d100.txt', 'r', encoding='utf-8') as f:
# print(f.read())
f = open('C:/Users/Administrator/Desktop/d100.txt', 'r', encoding='utf-8')
#每次读取一行
#for line in f.readlines():
# print(line.strip())
#每次最多读取size个字符(r模式)的内容
s = f.read(50)
print(s,end='')
while 1:
s = f.read(50)
if len(s) <=0:
break
print(s,end='')
f.close()
#写文件 w模式 覆盖写 a模式 追加写
w = open('C:/Users/Administrator/Desktop/d100.txt', 'a', encoding='utf-8')
w.write("bbbb")
#换行写
w.write("\nccc")
w.close()