473,729 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to I print without newline ?

Hi !

I want to print, but without newline. I want to create a progress for
ftp, but the print is drop a newline for every percent.
I want like this:

0% 25% 50% 75% 100%

But this happening:
0%
25%
50%
75%
100%

How to I prevent the newlines ?

Thanx for help:
FT
Jul 18 '05 #1
4 7210
> I want to print, but without newline. I want to create a progress for
ftp, but the print is drop a newline for every percent.
I want like this:

0% 25% 50% 75% 100%

But this happening:
0%
25%
50%
75%
100%

How to I prevent the newlines ?


Since you want spaces between the values, a comma at the end of the print
statement will do the trick:
for p in ( 0, 25, 50, 75, 100 ): .... print '%s%%' % p,
....
0% 25% 50% 75% 100%
In the more general case, where you want complete control and want to be
able to prevent this extra space, use sys.stdout.writ e():
for i in xrange(20):

.... sys.stdout.writ e( '+' )
....
+++++++++++++++ +++++>>>

Note that there wasn't a newline at the end. You'll need to do a
sys.stdout.writ e('\n') when you want one.

-Mike
Jul 18 '05 #2

<fo***********@ anonym.hu> wrote in message
news:ma******** *************** **************@ python.org...
Hi !

I want to print, but without newline. I want to create a progress for
ftp, but the print is drop a newline for every percent.
I want like this:

0% 25% 50% 75% 100%

But this happening:
0%
25%
50%
75%
100%

How to I prevent the newlines ?

Thanx for help:
FT

Jul 18 '05 #3
Here's a progressbar class I wrote some time ago, hope it helps.

-Larry

class progressbarClas s:
def __init__(self, finalcount, progresschar=No ne):
import sys
self.finalcount =finalcount
self.blockcount =0
#
# See if caller passed me a character to use on the
# progress bar (like "*"). If not use the block
# character that makes it look like a real progress
# bar.
#
if not progresschar: self.block=chr( 178)
else: self.block=prog resschar
#
# Get pointer to sys.stdout so I can use the write/flush
# methods to display the progress bar.
#
self.f=sys.stdo ut
#
# If the final count is zero, don't start the progress gauge
#
if not self.finalcount : return
self.f.write('\ n------------------ %
Progress -------------------1\n')
self.f.write(' 1 2 3 4 5 6 7 8 9 0\n')
self.f.write('----0----0----0----0----0----0----0----0----0----0\n')
return

def progress(self, count):
#
# Make sure I don't try to go off the end (e.g. >100%)
#
count=min(count , self.finalcount )
#
# If finalcount is zero, I'm done
#
if self.finalcount :
percentcomplete =int(round(100* count/self.finalcount ))
if percentcomplete < 1: percentcomplete =1
else:
percentcomplete =100

#print "percentcomplet e=",percentcomp lete
blockcount=int( percentcomplete/2)
#print "blockcount=",b lockcount
if blockcount > self.blockcount :
for i in range(self.bloc kcount,blockcou nt):
self.f.write(se lf.block)
self.f.flush()

if percentcomplete == 100: self.f.write("\ n")
self.blockcount =blockcount
return

if __name__ == "__main__":
from time import sleep
pb=progressbarC lass(8,"*")
count=0
while count<9:
count+=1
pb.progress(cou nt)
sleep(0.2)

pb=progressbarC lass(100)
pb.progress(20)
sleep(0.2)
pb.progress(47)
sleep(0.2)
pb.progress(90)
sleep(0.2)
pb.progress(100 )
print "testing 1:"
pb=progressbarC lass(1)
pb.progress(1)

<fo***********@ anonym.hu> wrote in message
news:ma******** *************** **************@ python.org...
Hi !

I want to print, but without newline. I want to create a progress for
ftp, but the print is drop a newline for every percent.
I want like this:

0% 25% 50% 75% 100%

But this happening:
0%
25%
50%
75%
100%

How to I prevent the newlines ?

Thanx for help:
FT

Jul 18 '05 #4
fo***********@a nonym.hu wrote:
I want to print, but without newline. I want to create a progress for
ftp, but the print is drop a newline for every percent.
I want like this:

0% 25% 50% 75% 100%

But this happening:
0%
25%
50%
75%
100%

How to I prevent the newlines ?


One option:

s = [ 0, 25, 50, 75, 100 ]
for p in s:
percent = "%d%%" % ( p, )
print percent,

Another option:

from sys import stdout
s = [ 0, 25, 50, 75, 100 ]
for p in s:
stdout.write( "%d%% " % ( p, ) )
stdout.write( "\n" )

--
Chris Herborth ch****@cryptoca rd.com
Documentation Overlord, CRYPTOCard Corp. http://www.cryptocard.com/
Never send a monster to do the work of an evil scientist.
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
4164
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn' anything similar you like. Would make my life so much easier. Often I start with a nice and short print statement, then there happen to be more arguments and neat formatting becomes more important and as a result I find myself
9
22173
by: Paul Watson | last post by:
I thought that using a comma at the end of a print statement would suppress printing of a newline. Am I misunderstanding this feature? How can I use print and not have a newline appended at the end? C:\src\projects\test1>python -c "import sys;print sys.version, 'running on', sys.platform" 2.3.4 (#53, May 25 2004, 21:17:02) running on win32 C:\src\projects\test1>python -c "print 'here'," >jjj
14
2911
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version: $Revision: 0.0 $
2
5127
by: jamesthiele.usenet | last post by:
I recently ran into the issue with 'print' were, as it says on the web page called "Python Gotchas" (http://www.ferg.org/projects/python_gotchas.html): The Python Language Reference Manual says, about the print statement, A "\n" character is written at the end, unless the print statement ends with a comma. What it doesn't say is that if the print statement does end with a
0
1832
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html There is also a wiki page that collects the ideas: http://wiki.python.org/moin/PrintAsFunction There is the will to keep the printing operation very simple for the most common situation, but at the same time to make it flexible (optional no...
2
1684
by: Karlo Lozovina | last post by:
Consider this short script: --- from time import time, sleep st = time() print 'Start: %f, ' % st, sleep(10) sp = time() print 'Stop: %f, Duration: %f' % (sp, (st - sp))
11
2072
by: A.M | last post by:
Hi, I found print much more flexible that write method. Can I use print instead of file.write method? Thank you,
3
2109
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for improvement. And of course it's possible there's some serious "gotcha" I've overlooked. Thus I welcome any and all comments. If there's some agreement that this proposal is worth further consideration then I'll re-submit a formal document in...
2
11019
by: Phoe6 | last post by:
print and softspace in python In python, whenever you use >>>print statement it will append a newline by default. If you don't want newline to be appended, you got use a comma at the end (>>>print 10,) When, you have a list of characters and want them to be printed together a string using a for loop, there was observation that no matter what there was space coming between the characters. No split or join methods helped. print e, a b c
0
8936
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9298
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9226
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9166
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6028
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4538
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2705
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.