问题出在标题中.
我想在python中做到这一点 .我想在c中的这个例子中做些什么:
#include <stdio.h>
int main() {
int i;
for (i=0; i<10; i++) printf(".");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
..........
Run Code Online (Sandbox Code Playgroud)
在Python中:
>>> for i in xrange(0,10): print '.'
.
.
.
.
.
.
.
.
.
.
>>> for i in xrange(0,10): print '.',
. . . . . . . . . .
Run Code Online (Sandbox Code Playgroud)
在Python中print会添加一个\n或一个空格,我该如何避免呢?现在,这只是一个例子.不要告诉我,我可以先构建一个字符串然后打印它.我想知道如何"附加"字符串stdout.
Python的解释器默认启用输出缓冲sys.stdout吗?
如果答案是肯定的,那么禁用它的所有方法是什么?
建议到目前为止:
-u命令行开关sys.stdout在每次写入后刷新的对象PYTHONUNBUFFEREDenv varsys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)是否有任何其他方式来设置一些全局标志sys/ sys.stdout程序执行过程中?
我有一个用于仿真的python脚本,一个for循环要花很长时间,每个循环要花不同的时间,因此我.在每个循环后打印一个,以监视它运行的速度和经过的时间。for脚本运行时的声明。
for something:
do something
print '.',
Run Code Online (Sandbox Code Playgroud)
但是,当我在终端中的iPython中运行脚本时,点并不会一一打印,而是在循环结束时一次打印所有点,这使整个过程变得毫无意义。如何在运行时内联打印点?
目前,当我
from __future__ import print_function
从Python 2.7.6开始,我显然在添加flush关键字参数之前得到了print()版本,根据文档在Python 3.3中进行了操作.我的系统(Ubuntu)中安装的Python3是Python 3.4,我验证了它的print()函数有flush参数.
如何print()从3.4 导入功能?从哪里__future__获得较旧的打印功能?
python ×4
buffered ×1
flush ×1
ipython ×1
macos ×1
newline ×1
printing ×1
python-2.7 ×1
python-2.x ×1
python-3.x ×1
stdout ×1
terminal ×1