- 文件创建
f=open("t.txt","w")//没有写路径,默认当前路径下 f.write("哈哈哈")
import os src_file="D://a/a/tt.txt" fpath,fname=os.path.split(src_file) if not os.path.exists(fpath): os.makedirs(fpath) f=open("D://a/a/tt.txt","w") f.write("哈哈哈") f.close()
文件读取src="D://d/a/ttt.txt" f=open(src) c=f.read() print(c)
src="D://d/a/ttt.txt" f=open(src) #c=f.read() #c=f.readline()/读取一行 c=f.readlines()//以列表形式读取所有数据 print(c)['today is sunday\n', 'yest\n', 'very good']
for i in f: print(i,end="")//迭代但是效率低
Python文件
最新推荐文章于 2019-04-24 15:59:29 发布