在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())

 

posted @ 2018-09-24 06:33  tbwbnny  阅读(542)  评论(0编辑  收藏  举报