码迷,mamicode.com
首页 > 编程语言 > 详细

python 数据类型---文件二

时间:2016-12-20 23:17:53      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:with   time   避免   std   二进制   缓冲区   sys   int   进制   

1.打印进度条

import sys,time
for i in range(20):
    sys.stdout.write("#")
    sys.stdout.flush() #不等缓冲区满就打印输出
    time.sleep(0.1)

2. "r+", "w+", "a+" ,"rb"  读写模式, 写读模式, 追加读写模式, 二进制读写模式(一般用于网络传输)

3. with 用法

  Sytanx  ‘‘‘ with open("file1.txt") as obj1, open("file2.txt") as ojb2:  ‘‘‘

 with 用于避免忘记关闭文件而生

with open("lyric.txt", "r", encoding="utf-8") as f,      open("lyric_2.txt", "r", encoding="utf-8") as f2:
    for line in f:
        print(line)

 

python 数据类型---文件二

标签:with   time   避免   std   二进制   缓冲区   sys   int   进制   

原文地址:http://www.cnblogs.com/frankb/p/6204571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!