#!/usr/bin/python # -*- coding:utf-8 -*- # 我希望的是,在while循环中,每次打印都能打印文件中新写入的字符,然后每次写入,都能立刻在文件中看到写入的字符 with open("test.txt", "wb+") as fp: while True: # 打印文件中的内容 # 清空文件,raw_input一个字符并把字符写入文件 ^^^^^^^^^^^^^
with open('/tmp/realtime.txt', 'w+') as fp: while True: fp.write(str(i)+' ') fp.flush() time.sleep(3)
37,722
社区成员
34,238
社区内容
加载中
试试用AI创作助手写篇文章吧