首页 > 代码库 > python 数据类型---文件二

python 数据类型---文件二

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 数据类型---文件二