python入门笔记-文本读写
来源:互联网 发布:地理信息系统算法试卷 编辑:程序博客网 时间:2024/06/05 20:44
保存文件到python.exe的安装目录下,命令行运行python,输入读写命令.。否则要在操作的文本文件名称前加路径
在读写前要赋予文件读写的权限f=open(),不使用之后要关闭文件f.close()
1.文本文件内容
2.读取文件
以读的方式打开文件 f=open('test.txt','r')
读取方式
f.read()表示按文本文件的保存方式读取到文件尾。
f.seek(0)表示跳到文件开始位置。
f.readline()逐行读取文本文件。
f.readlines()读取所有行,通过for循环可以读出数据。
f.close()关闭文件----读取文件后不用了要关闭。-
3.写文件
以写的方式打开文件 f=open('test.txt','w')
写一行内容f.write('abc')----覆盖原来已有内容
写多行内容f.writelines(['a\n','b\n','c\n'])---覆盖原来内容
4.查看文本信息
f = open('test.txt')
print '文件名:', f.name
print '是否处于关闭状态:', f.closed
print '打开的模式:', f.mode
0 0
- python入门笔记-文本读写
- python 文本读写操作
- Python读写文本文档详解
- Python 读写文本(open)
- 【Python 笔记】文件读写
- python 读写 excel 笔记
- python 读写文本文件笔记
- Python文本读取笔记
- python文本读写,with open as
- [C++]入门笔记5.文本
- 文本挖掘 入门笔记1
- Python学习笔记--文件读写
- [python 笔记5]文件读写
- python学习笔记 文件读写
- python的文件读写笔记
- 零基础学python-3.7 另一个程序 python读写文本
- Python笔记-文本字符串格式化
- 读写文本
- oracle 中的 V$SQL存储了哪些东西?
- C#中调用c++的dll如何适应32位跟64位的平台
- 网络编程socket之listen函数
- 查看oracle的process和session设置的最大值和峰值
- Robot: Duplicate Keywords in Library and Resource Keywords
- python入门笔记-文本读写
- 【Hibernate】详解Hibernate中的inverse=”true”
- Robot: Include and Exclude Tags
- May Challenge 2015(CodeChef 2015年5月月赛)
- FreeType 学习笔记
- filetimetosystemtime函数将filetime转化systemtime后所得的时间依旧是一种UTC时间
- eclipse修改web项目部署路径
- Robot: Set Log Level
- Sicily 14513. Aaah!