您的位置:首页 > 编程语言 > Python开发

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...

给主人留下些什么吧!~~

评论热议
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: