在pycharm中打印文件a
Posted 0312abcde
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在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())
以上是关于在pycharm中打印文件a的主要内容,如果未能解决你的问题,请参考以下文章