473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Printing dots in single-line

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
11 7531
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
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
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
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
This is the 4th gotch on my Python gotchas page:
http://www.ferg.org/projects/python_gotchas.html
Jul 18 '05 #6
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
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
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maileen | last post by:
Hi, I have 2 questions : 1. - I want to print from my ASP page directly to my network printer. For this i use the following code, but everytime, my document to print is sent to local and...
0
by: JF Turcotte | last post by:
Hi I'm unsuccessfully trying to print a form's image under VB.NET. To print under .NET is a real pain in the , I find it to be complex, lenghty, confusing, upsetting and ultimately not to be...
0
by: Chris | last post by:
Hi, I found this code to send print direct to printer. It works perfect. Imports System Imports System.Text Imports System.Runtime.InteropServices <StructLayout(LayoutKind.Sequential)> _...
2
by: qumpus | last post by:
My program right now generates USPS style shipping label using System.Drawing.Graphics. It works fine except that the printer prints really slowly. I want to make my program take advantage of true...
3
by: Mika M | last post by:
Hi all! I have made an application for printing simple barcode labels using PrintDocument object, and it's working fine. Barcode printer that I use is attached to the computer, and this...
7
by: DazedAndConfused | last post by:
I have a 8.5 x 11 landscape document with about 1/4 inch of space on the left and right where there is no print. The document displays perfect in print preview, but when I print it, about 1/2 inch...
3
by: D Witherspoon | last post by:
No matter what I do the default paper size is always either A3 or 11 by 8.5 .. Here is the code. Dim dlg As DialogResult pd.DocumentName = "Weld Image" Dim pkPaperSize As New...
10
by: Fabian Steiner | last post by:
Hello! I am currently working on an application where the user is able to create new worksheets and to delete existing ones. All of these worksheets have the same structure (--> template?), only...
4
by: beertje | last post by:
This is a very newbie question for my first post, perhaps appropriately. I want to print '....' gradually, as a progress indicator. I have a for-loop that every 10 steps executes: print '.', ...
4
intOwnsVoid
by: intOwnsVoid | last post by:
Point.h #pragma once #include <iostream> using namespace std; class Point {
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.