This is a stumbling block for me. Is there
a better way to output *just* what I want?
I want the output "foobar" print "foo"; print "bar"
foo
bar print "foo",; print "bar"
foo bar
I know that I can do it in one go with
print "%s%s" % ("foo", "bar")
foobar
But the prints happen in different places
in the program.
Is there a "lower level" way to output
chars other than 'print'?
Thanks,
Tobiah 5 7781
Tobiah <to**@rcsreg.com> pisze: Is there a "lower level" way to output chars other than 'print'?
sys.stdout.write()
--
Jarek Zgoda
Registered Linux User #-1 http://www.zgoda.biz/ JID:ja***@jabberpl.org http://zgoda.jogger.pl/
Tobiah wrote: But the prints happen in different places in the program.
You can adjust this behavior with sys.stdout.softspace, but ultimately
the print facility is not really ideal for when you need fine control
over output.
Is there a "lower level" way to output chars other than 'print'?
Yep, call sys.stdout.write directly.
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ It [freedom] must be demanded by the oppressed.
\__/ Dr. Martin Luther King, Jr.
Hi!
Erik Max Francis <ma*@alcyone.com> wrote in news:3F64DEF7.F98CFAB8
@alcyone.com: Is there a "lower level" way to output chars other than 'print'?
Yep, call sys.stdout.write directly.
Is it then also possible to "jump back" a few chars to, e.g., have a
progress... (damn, I forgot that word) however, that shows the percentage
of progress? Like print "25%" and then jump back three chars and write
"26%"?
And then, on my Linux machine, such things just don't happen at all. E.g.
in a loop like...
for i in range(1000):
j = pow(2,i)
if j%100: print "#",
....I will get nothing for a long time and then ten "#" chars at one time.
Is there a solution for that?
Bye
Tobias
Tobias Pfeiffer <Bo**************@web.de> wrote in
news:bk************@ID-162581.news.uni-berlin.de: Yep, call sys.stdout.write directly. Is it then also possible to "jump back" a few chars to, e.g., have a progress... (damn, I forgot that word) however, that shows the percentage of progress? Like print "25%" and then jump back three chars and write "26%"?
Back three characters: "\b\b\b"
Back to start of line: "\r"
e.g. for i in range(10000):
.... j = pow(2,i)
.... if j%100:
.... sys.stdout.write("\b"+"/-\\|"[i%4])
....
And then, on my Linux machine, such things just don't happen at all. E.g. in a loop like...
for i in range(1000): j = pow(2,i) if j%100: print "#",
...I will get nothing for a long time and then ten "#" chars at one time. Is there a solution for that?
Maybe sys.stdout.flush()?
--
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?
Tobias Pfeiffer wrote: Is it then also possible to "jump back" a few chars to, e.g., have a progress... (damn, I forgot that word) however, that shows the percentage of progress? Like print "25%" and then jump back three chars and write "26%"?
That's typically done with printing BS characters to back up one space
('\b') or CR characters to return the carriage to the beginning of the
line ('\r'). Note that strictly speaking these may not have the desired
effect, although in most environments they will.
And then, on my Linux machine, such things just don't happen at all. E.g. in a loop like...
for i in range(1000): j = pow(2,i) if j%100: print "#",
...I will get nothing for a long time and then ten "#" chars at one time. Is there a solution for that?
You're encounting buffering; use sys.stdout.write directly and call
sys.stdout.flush() after you've printed some partial output.
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Custom reconciles us to everything.
\__/ Edmund Burke This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nancy Drew |
last post by:
this script used to upload files to the server without any issue:
$oFTPConn = ftp_connect($sFtpServer,21,600) or die("Unable to connect ot
$sFTPServer!"); //login to the ftp server and upload the...
|
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'...
|
by: fowlertrainer |
last post by:
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:...
|
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...
|
by: Michael Foord |
last post by:
Here's a little oddity with 'print' being a reserved word...
>>> class thing:
pass
>>> something = thing()
>>> something.print = 3
SyntaxError: invalid syntax
>>> print something.__dict__...
|
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:...
|
by: Howard Kaikow |
last post by:
I have never seen WriteLine fail to produce a NewLine, at least, not until
now:
I was playing with an example given on pages 51-52 of the book "A Visual
Basic 6 Programmer's Toolkit".
The book...
|
by: sixtyfootersdude |
last post by:
Good Morning!
I am just starting to learn perl and I am somewhat mistifide about when I should do:
print("@input");
and when I should do:
print(@input)
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |