The question is in the title.
I'd like to do it in python. What I'd like to do in this example in c:
#include <stdio.h>
int main() {
int i;
for (i=0; i<10; i++) printf(".");
return 0;
}
Output:
..........
In Python:
>>> for i in xrange(0,10): print '.'
.
.
.
.
.
.
.
.
.
.
>>> for i in xrange(0,10): print '.',
. . . . . . . . . .
In Python print
will add a \n
or a space, how can I avoid that? Now, it's just an example. Don't tell me I can first build a string then print it. I'd like to know how to "append" strings to stdout
.
i recently had the same problem..
i solved it by doing:
this works on both unix and windows ... have not tested it on macosx ...
hth
The new (as of Python 3.0)
print
function has an optionalend
parameter that lets you modify the ending character. There's alsosep
for separator.You can try:
Here's a general way of printing without inserting a newline.
Python 3
In Python 3 it is very simple to implement
You will notice that all the above answers are correct. But I wanted to make a shortcut to always writing the " end='' " parameter in the end.
You could define a function like
It would accept all the number of parameters. Even it will accept all the other parameters like file, flush ,etc and with the same name.
Using functools.partial to create a new function called printf
Easy way to wrap a function with default parameters.