文件的先关操作

1,r:可读

2,w:写

3,a:追击模式

4,r+ 可读写文件(可读,可写,可追击)

5,w+ 写读模式

6,a+ 追加模式

7,rb   wb  ab  表示二进制文件

二:文件常用操作

1,read() 全部读取

2,readline()只读取一行操作

3,readlines()把文章内容以换行符分割,并生成list 

    ['我越无所适从\n', '越会事与愿违\n', '在交错的时空\n', '灵魂加速下坠\n', 'Here we are, here we are, here we are\n'

4,seek 移动光标位置 文件名.seek(写把光标移到哪里)

5,tell 获取光标的位置 文件名.tell()

6,flush 刷新

import sys,time         #加载模块

for i in range(40):
    sys.stdout.write("#")
    sys.stdout.flush()          #flush 强制刷新缓存到内存的数据写入硬盘
    time.sleep(0.1) 
View Code

7,truncate  截断

  truncate跟光标位置无关,从文件首部开始截取字符;如果是truncate(0)会把文件清空

8,with 语句

 

其他内容参考另一篇博客

 

 




posted @ 2017-11-18 13:11  冰滴的眼泪  阅读(151)  评论(0编辑  收藏  举报