摘要: 文件上下文管理器自动关闭文件 """with open() as 名字student.txthello worldword ppt excel​"""## 读取student的内容复制到b中with open("student.txt","r") as f,open("b.txt","w+") as 阅读全文
posted @ 2021-04-23 17:50 默默努力的路人甲 阅读(34) 评论(0) 推荐(0)
摘要: """创建一个100行的文件,并且每一行随机生成一个100以内的整数"""​import randomf = open("a.txt","w+")​for i in range(100): f.write(str(random.randint(1,100))+"\n")##类型必须都相同的才能拼接​ 阅读全文
posted @ 2021-04-23 17:41 默默努力的路人甲 阅读(102) 评论(0) 推荐(0)
摘要: 文件读取 student.txt hello worldword ppt excel 读取一行 f = open("student.txt","r+")​print(f.readline())##读取一行​f.close()hello world 读取每一行并且存入列表中 f = open("stu 阅读全文
posted @ 2021-04-23 17:31 默默努力的路人甲 阅读(129) 评论(0) 推荐(0)
摘要: 文件的读取和写入 写入 f = open("nothing.txt","r")##默认为r读##因为在目录中并没有这个文件所以会报错f.close()##记得要关闭FileNotFoundError: [Errno 2] No such file or directory: 'nothing.txt 阅读全文
posted @ 2021-04-23 17:08 默默努力的路人甲 阅读(134) 评论(0) 推荐(0)