赞
踩
写入
with open('test.txt','w') as f:
f.write("hello,world!!!")
读取
read(x) 按字符读取,x默认为-1,表示全部内容
readline() 读入一行
readlines() 以列表形式全部读入
情形一:分行读入,逐行处理
fo=open('test.txt','r',encoding='utf-8')
for line in fo: # fo.read(x),读取前x个字符
print(line)
fo.close()
情形二:一次读入,分行处理
with open('test.txt','r',encoding='utf-8') as fo:
print(fo.read())
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。