By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

Printing dots in single-line

P: n/a
Hey there,

I want to print some dots in a single-line while my program loads or does
something. I tried with he following but it didn't work :(.

while 1:
print '.',

Prints line of dots separated by a whitespace (. . . . . . etc). Is there a
way I can get it to display them without that white space (.......etc)?

Thanks
Jul 18 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On Thu, 13 Nov 2003 12:22:01 -0300, <tr****@nic.nac.wdyn.de> wrote:
Hey there,

I want to print some dots in a single-line while my program loads or does
something. I tried with he following but it didn't work :(.

while 1:
print '.',

Prints line of dots separated by a whitespace (. . . . . . etc). Is there a
way I can get it to display them without that white space (.......etc)?


import sys

while 1:
sys.stdout.write(".")
Jul 18 '05 #2

P: n/a
At 08:22 AM 11/13/2003, tr****@nic.nac.wdyn.de wrote:
Hey there,

I want to print some dots in a single-line while my program loads or does
something. I tried with he following but it didn't work :(.

while 1:
print '.',

Prints line of dots separated by a whitespace (. . . . . . etc). Is there a
way I can get it to display them without that white space (.......etc)?


Try (depending on the output device)
while 1:
print '.\b',

Bob Gailer
bg*****@alum.rpi.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003

Jul 18 '05 #3

P: n/a
Bob Gailer wrote:
At 08:22 AM 11/13/2003, tr****@nic.nac.wdyn.de wrote:
Prints line of dots separated by a whitespace (. . . . . . etc). Is
there a
way I can get it to display them without that white space
(.......etc)?


Try (depending on the output device)
while 1:
print '.\b',


A _far_ superior solution would be to simply not print the trailing
spaces in the first place:

while True:
sys.stdout.write('.')
sys.stdout.flush()

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \
\__/ Love is like war: easy to begin but very hard to stop.
-- H.L. Mencken
Jul 18 '05 #4

P: n/a
Bob Gailer <bg*****@alum.rpi.edu> wrote in
news:ma************************************@python .org:
while 1:
print '.',

Prints line of dots separated by a whitespace (. . . . . . etc). Is
there a way I can get it to display them without that white space
(.......etc)?


Try (depending on the output device)
while 1:
print '.\b',


Yuck.

Either suppress the whitespace:

import sys
for i in range(10):
sys.stdout.softspace=False
print '.',

or, much simpler, just don't use print:

for i in range(10):
sys.stdout.write('.')

The reason I say that 'write' is simpler is that the softspace attribute
works in a slightly confusing manner. You have to set it false every time
before you print something if you don't want Python putting a leading space
before the string it outputs. It gets sets true after each item that is
printed unless a newline has just been output.

--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #5

P: n/a
This is the 4th gotch on my Python gotchas page:
http://www.ferg.org/projects/python_gotchas.html
Jul 18 '05 #6

P: n/a
On Thu, 13 Nov 2003 12:22:01 -0300, trofe wrote:
Hey there,

I want to print some dots in a single-line while my program loads or
does something. I tried with he following but it didn't work :(.

while 1:
print '.',

Prints line of dots separated by a whitespace (. . . . . . etc). Is
there a way I can get it to display them without that white space
(.......etc)?


print('.' * n)

where n is the number of dots you want to print.

Incidentally, I saw other responses, and most of them suggest
sys.stdout.write(). Is there a reason that is preferable over the
solution above?

Alok
Jul 18 '05 #7

P: n/a
Alok Singhal wrote:
Incidentally, I saw other responses, and most of them suggest
sys.stdout.write(). Is there a reason that is preferable over the
solution above?


Yes: the print statement is an abomination. It is a special-case syntax for
a task that requires no special syntax, and will hopefully be deprecated in
the future, the sooner the better.

It is also not as general as sys.stdout.write. It may be important that the
dots are printed in separate statements. For example, the dots could be
used as a progress indicator.
--
Rainer Deyke - ra*****@eldwood.com - http://eldwood.com
Jul 18 '05 #8

P: n/a
Alok Singhal wrote:
On Thu, 13 Nov 2003 12:22:01 -0300, trofe wrote:
Hey there,

I want to print some dots in a single-line while my program loads or
does something. I tried with he following but it didn't work :(.

while 1:
print '.',

Prints line of dots separated by a whitespace (. . . . . . etc). Is
there a way I can get it to display them without that white space
(.......etc)?


print('.' * n)

where n is the number of dots you want to print.

Incidentally, I saw other responses, and most of them suggest
sys.stdout.write(). Is there a reason that is preferable over the
solution above?


The solution you give will not work when you want to do processing
between each dot.

Jul 18 '05 #9

P: n/a
"Rainer Deyke" <ra*****@eldwood.com> writes:
Yes: the print statement is an abomination. It is a special-case syntax for
a task that requires no special syntax, and will hopefully be deprecated in
the future, the sooner the better.


Are you kidding? The example I keep asking about is the addition
operator (+). Why does anyone need to say 2+2 when they can say
2-(-2)? The addition operator is a special case syntax for the
subtraction operator where none is needed. Should we deprecate it?
I'd rather say that a practical language needs to make concessions to
the way users actually think.
Jul 18 '05 #10

P: n/a
Paul Rubin wrote:
"Rainer Deyke" <ra*****@eldwood.com> writes:

Yes: the print statement is an abomination. It is a special-case syntax for
a task that requires no special syntax, and will hopefully be deprecated in
the future, the sooner the better.


Are you kidding? The example I keep asking about is the addition
operator (+). Why does anyone need to say 2+2 when they can say
2-(-2)? The addition operator is a special case syntax for the
subtraction operator where none is needed. Should we deprecate it?
I'd rather say that a practical language needs to make concessions to
the way users actually think.

Well, okay then :) Personally, print bothers me because there is no
receiver. As an OO developer, I'm used to thinking usually iin terms of
"object.method" and the fact that print is just sorta this standalone
thing out there with no receiver doesn't match the way I think.
However, it's not really a function either as it doesn't use function
syntax. It's just sorta there. It really doesn't fit in with any of the
basic idioms I use when thinking about developing software

Jul 18 '05 #11

P: n/a
"Rainer Deyke" <ra*****@eldwood.com> writes:
Alok Singhal wrote:
Incidentally, I saw other responses, and most of them suggest
sys.stdout.write(). Is there a reason that is preferable over the
solution above?


Yes: the print statement is an abomination.


Says you.

I mean, just take a look at Joe Strout's brilliant little "python
for beginners" page. Replace all print-statements with
sys.stdout.write( string.join(map(str, args)) + "\n") and you
surely won't get any new beginners. And That Would Be A Very Bad
Thing.
-- Fredrik Lundh, 27 Aug 1996

Cheers,
mwh

--
: Giant screaming pieces of excrement, they are.
I have a feeling that some of the people in here have a
MUCH more exciting time relieving themselves than I do.
-- Mike Sphar & Dave Brown, asr
Jul 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.