doing successive prints without space in between

Tim Williams listserver at tdw.net
Wed Aug 11 15:08:14 CEST 2004


On Fri, 2 Jul 2004 20:59:39 GMT, Harry George <harry.g.george at boeing.com>
wrote:
> Jon Perez <jbperez808 at yahoo.com> writes:
>
> > I'd like to print a series of successive periods as a
> > progress status in a command line script using python.
> > Unforutnately, if I do a series of successive
> >
> > print ".",
> >
> > I get a space in between.  Is there any way to avoid
> > this?
>
> This show up regularly and might be a FAQ.  The print is trying to
> help you out.  If you want total control, go to the lower levels:
>
> wr=sys.stdout  #redirect as desired
>
> def myprint(txt):
>    wr.write(txt)   #raw print
>    wr.flush()      #flush the dots as they occur
>
> for i in range(100):
>    do_something()
>    myprint('.')
>
> myprint('\n')

Apologies for posting roughly the same solution in two posts :-)

for i in range(100):
   do_something()
   print '\b.',

:-)







More information about the Python-list mailing list