473,807 Members | 2,820 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 7214
> 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
4182
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
22175
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
2922
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
5131
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
1837
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
1690
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
2082
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
2115
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
11043
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
9720
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
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10626
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
10112
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...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
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
5546
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...
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3854
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.