简单的文件操作

#Author:yue
# f = open("yue",'r',encoding='utf8')
# g = open("test")
# data = f.read()
# print(data)
# print(g.read())
#
# f.close()
# g.close()

# # 文件打开模式,只读,只写
# print(f.readable())
# print(f.readline())
# print(f.readlines())

# f = open("yue1",'w',encoding='utf8')
# f.write('12345')
# f.write('45645 ')
# f.writelines(['yue ','xue ']) 文件内容只能是字符串

# 追加
# f = open("yue1",'a',encoding='utf8')
# f.write('追加的内容') 追加的本质时写操作
#
# f.close()

# 文件处理的其他操作
f = open("yue1",'r',encoding='utf8')
data = f.readlines()
f.close()

g = open('yue2','w',encoding='utf8')
gdata = g.writelines(data[1])
g.close()
原文地址:https://www.cnblogs.com/Syue/p/9545593.html