Python文件基本操作
来源:互联网 发布:webpackdevserver端口 编辑:程序博客网 时间:2024/06/05 14:48
#author F# data = open("test.txt", encoding="utf-8").read()# f = open("test.txt", 'r', encoding="utf-8") #文件句柄 r->读# data = f.read()# data2 = f.read()# print(f)# print(data)# print('-----------data------%s---' % data2) #data2无内容 原因?文件指针在末尾# f.close()# file = open("test.txt", 'w', encoding="utf-8") #文件句柄 w->创建新文件 会删除原来文件# file.write("阿斯顿哈苏德库哈斯,\n")# file.write("vs的风格地方个地方官 ")# file = open("test.txt", 'a', encoding="utf-8") #a->追加# file.write("\n打算肯德基,\n")# file.write("大厦哈哈哈 ")# f = open("test.txt", 'r', encoding="utf-8") #文件句柄 r->读# print(f.readline())# print(f.readline())# for i in range(2):# print(f.readline())# print(f.readlines()) #打印列表 每行一个元素 中间有个空行是因为有个\nf = open("test.txt", 'r', encoding="utf-8") #文件句柄 r->读# for line in f.readlines():# print(line.strip())#low loop# for index, line in enumerate(f.readlines()):# if index == 9:# print("-----我是分割线-----")# continue# print(line.strip())#high loopcount = 0for line in f: #f成为了迭代器 if count == 9: print("-----我是分割线-----") count += 1 continue print(line) count += 1f.close()
阅读全文
0 0
- Python文件基本操作
- python基本文件操作
- Python 文件基本操作
- Python 文件基本操作
- Python文件基本操作
- Python基本文件操作
- python读写文件基本操作
- Python基础--基本文件操作
- Python 中的基本文件操作
- 小白学Python(二) 基本文件操作
- python对文件的基本操作
- python文件路径的基本操作
- Python基础--基本文件操作二
- Python学习笔记之:文件基本操作
- Python零碎知识(3):对文件的基本操作
- python对文件的几大基本操作
- Python基本语法_文件操作_读写函数详解
- Python 基本类型操作
- 如何让ArrayList<Integer>添加一个String类型的元素呢
- c++ 90,91,92
- UE4添加枪口火焰效果
- springmvc学习-框架原理图
- Kth smallest element (in a sorted matrix ; In a BST tree ; In two sorted array)
- Python文件基本操作
- SPA
- hdoj1074 Doing Homework(好题呀,状态压缩+DP)
- 优先队列 CodeForces
- 软件设计之面向过程
- 一些常见的Oracle时间、日期的用法
- Strtus2与Spring-MVC的区别?
- X86 BSWAP指令详解
- android中如何让设配开启横竖屏