摘要: #1、编写文件copy工具 oldpath=input('请输入源文件地址:') newpath=input('请输入新文件存放地址: ') with open(oldpath,mode='rt',encoding='utf-8')as file1,\ open(newpath,mode='wt', 阅读全文
posted @ 2020-03-13 23:02 江湖有梦 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 一、with的使用with open('a.txt',mode='rt') as f1: res=f1.read() print(res)# f1=open('a.txt',mode='rt')with方法可以在执行完子代码后自动关闭文件,节约内存空间。二、指定字符编码强调:t和b不能单独使用,必须跟r/w/a连用​t文本(默认的模式)1、读写都以str(unicode)为单位的2、... 阅读全文
posted @ 2020-03-13 18:11 江湖有梦 阅读(382) 评论(0) 推荐(0) 编辑
摘要: 一、打开文件 1.路径分隔符转义问题 ① open(r'C:\a\nb\c\d.txt') ②open('C:/a/nb/c/d.txt') 2.打开方法 file1=open(r'aaa/a.txt',mode='rt')#这里的file1是一个变量名,占用应用程序内存空间 3.操作文件 应用程序 阅读全文
posted @ 2020-03-13 18:08 江湖有梦 阅读(272) 评论(0) 推荐(0) 编辑