文件写入 & 读取

io.open():

some_file=io.open('somefile.txt','w+')

.close():

.flush():刷新缓存,好像有时没用?

.read(n):读取字符个数

.readline():读取一行字符:也可以指定字符个数

.readlines():返回所有行;也可以指定字符个数

.write():

.writelines():

some_file.writelines(['There is nothing here except\r','This stupid haiku'])

1)每次open打开,如果是‘w+’,直接清空;如果是‘r+’,则不会;如果是‘r+’,尽管可以修改内容,插入字符的位置为txt文件的第一行开头,附加内容是‘a+’;

猜你喜欢

转载自www.cnblogs.com/wllwqdeai/p/13198936.html
今日推荐