在pycharm中打印文件a

1.逐行打印

with open('a','r',encoding = 'gbk') as f: #with打开文件啊,用r模式。
    import sys,time   #调用模块sys,time来实现逐行打印
    for line in f:         #for循环文件a
        sys.stdout.flush  #用stdout,flush来实现在内存中,只保留一行字符
                                    串
        time.sleep(1)      #打印间隔时间为1秒
        print(line.strip())

2.打印中文

with open('a','r',encoding = 'gbk') as f: #with打开文件啊,用r模式。
    import sys,time   #调用模块sys,time来实现逐行打印
    for i in f:         #for循环文件a,把line替换成 i
        sys.stdout.flush  #用stdout,flush来实现在内存中,只保留一行字符
                                    串
        time.sleep(1)      #打印间隔时间为1秒
        print(i.strip())

猜你喜欢

转载自www.cnblogs.com/0312abcde/p/9694651.html