10 2018 档案

摘要:with opne("text.txt", encoding="utf8") as f, open("text2.txt", encoding="utf8") as f2 : pass with代码块执行完就自动close文件、 阅读全文
posted @ 2018-10-15 10:32 jeff9571 阅读(958) 评论(0) 推荐(0)
摘要:f = open("text.txt", encoding="utf8") for index,line in enumerate(f.readlines()): #文件对象的readlines返回的是list,enumerate方法是获取list的index和对应的内容 pass 阅读全文
posted @ 2018-10-10 15:52 jeff9571 阅读(2684) 评论(0) 推荐(0)
摘要:file = open("test.txt", encoding="utf8") #文档以utf8编码读取,不然默认gbk,中文会出现乱码 data = file. read() data2 = file.read() print(data2) #结果为空,第一次读完指针就停留在末尾,第二次读接着上 阅读全文
posted @ 2018-10-10 11:37 jeff9571 阅读(1698) 评论(0) 推荐(0)