file operate in python (open write read close )
2016-01-12 13:01
543 查看
1. file open:
fd = open(N1,N2):N1:path of the file to be open like '/home/warrior/Downloads/test.txt'
N2:some choiceable parameter
'r':read only 'w':write only 'r+':read and write 'a':write and will add content at the end of file
2. file read:
content = fd.read():read all content of the file
oneline = fd.readline():read one line content of the file
lastContent = fd.readlines():read the content from current vernier to the end of the file
3. file write:
fd.write(content):when opening in 'w' it will write content cover the original content
when opening in 'a' it will write content add at the end of the file but not start one new line again
fd.writelines(content): when opening in 'w' it will write content cover the original content
when opening in 'a' it will write content add at the end of the file and start one new line again
4. file close:
fd.close():when open one file must close it as you will not use it .
5. file others:
fd.seek(number):set the vernier of the file
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(25) | 评论(0) | 转发(0) |
0
上一篇:android studio logcat异常调试信息解析错误方法
下一篇:I/O of python (INPUT / OUTPUT)
相关热门文章
python 自动化测试平台 Robot ...
python 自动化测试平台 Robot ...
python snmp 自动化2-在python...
自动化测试详细测试计划 模板...
python snmp 自动化3-修改pyth...
linux dhcp peizhi roc
关于Unix文件的软链接
求教这个命令什么意思,我是新...
sed -e "/grep/d" 是什么意思...
谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议
fd = open(N1,N2):N1:path of the file to be open like '/home/warrior/Downloads/test.txt'
N2:some choiceable parameter
'r':read only 'w':write only 'r+':read and write 'a':write and will add content at the end of file
2. file read:
content = fd.read():read all content of the file
oneline = fd.readline():read one line content of the file
lastContent = fd.readlines():read the content from current vernier to the end of the file
3. file write:
fd.write(content):when opening in 'w' it will write content cover the original content
when opening in 'a' it will write content add at the end of the file but not start one new line again
fd.writelines(content): when opening in 'w' it will write content cover the original content
when opening in 'a' it will write content add at the end of the file and start one new line again
4. file close:
fd.close():when open one file must close it as you will not use it .
5. file others:
fd.seek(number):set the vernier of the file
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(25) | 评论(0) | 转发(0) |
0
上一篇:android studio logcat异常调试信息解析错误方法
下一篇:I/O of python (INPUT / OUTPUT)
相关热门文章
python 自动化测试平台 Robot ...
python 自动化测试平台 Robot ...
python snmp 自动化2-在python...
自动化测试详细测试计划 模板...
python snmp 自动化3-修改pyth...
linux dhcp peizhi roc
关于Unix文件的软链接
求教这个命令什么意思,我是新...
sed -e "/grep/d" 是什么意思...
谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议
相关文章推荐
- mac下pycharm设置python版本
- 29. Divide Two Integers leetcode python new season 2016
- leetcode之Convert Sorted List to Binary Search Tree
- leetcode之Convert Sorted Array to Binary Search Tree
- python中的lib的一些安装方法
- python脚本导入mysql中文乱码
- 28. Implement strStr() leetcode Python new season 2016
- WIN10 64bit python3.4 安装 numpy scipy matplotlib
- python代码段
- 27. Remove Element leetcode python 2016 new season
- Python 连接 MySQL数据库
- python数字图像处理(6):图像的批量处理
- python操作MySQL数据库
- python遍历文件夹并实现分级缩进显示
- Python -- str 类
- python中if __name__ == '__main__': 的解析
- python生成随机数组
- Python异常处理
- Python中的method
- Python下划线与命名规范