473,395 Members | 2,713 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,395 software developers and data experts.

Printing to console (No Scroll)

Hi,
How can I print to the console without having it scrolling to a new line for
each print statement?
I want to print a count down in the console, but for each count it scrolls
the screen (of course).

Is there another way?

Here is the simple script for now

print "Closing window in :"
for second in range(10):
time.sleep(1)
print `10-second` +" seconds"

thanks
/totte


Jul 18 '05 #1
11 5734
> How can I print to the console without having it scrolling to a new line
for each print statement?
I want to print a count down in the console, but for each count it scrolls
the screen (of course).


Use ncurses.

Diez
Jul 18 '05 #2
Totte Karlsson wrote:
Hi,
How can I print to the console without having it scrolling to a new line for
each print statement?
I want to print a count down in the console, but for each count it scrolls
the screen (of course).

Is there another way?

Here is the simple script for now

print "Closing window in :"
for second in range(10):
time.sleep(1)
print `10-second` +" seconds"

thanks
/totte


This works for me:

import time, sys
for second in range(10):
time.sleep(1)
sys.stdout.write(`10-second` + " seconds ")
sys.stdout.flush()
Jul 18 '05 #3
Any alternatives to ncurses? It seems like a overkill for this...
cheers
/totte
"Diez B. Roggisch" <de************@web.de> wrote in message
news:bu*************@news.t-online.com...
How can I print to the console without having it scrolling to a new line
for each print statement?
I want to print a count down in the console, but for each count it scrolls the screen (of course).


Use ncurses.

Diez
--
http://mail.python.org/mailman/listinfo/python-list



Jul 18 '05 #4
Totte Karlsson wrote:
Any alternatives to ncurses? It seems like a overkill for this...


Maybe you can use sys.stdout.write in conjunction with control-codes for
moving back the cursor to column one. But you'll have to lookup these for
yourself :)

Diez
Jul 18 '05 #5
"Diez B. Roggisch" wrote
Any alternatives to ncurses? It seems like a overkill for this...


Maybe you can use sys.stdout.write in conjunction with control-
codes for moving back the cursor to column one. But you'll have
to lookup these for yourself :)


I think \r is the control code (at least if you want to go back to the
start of the line):

import time, sys
for second in range(10):
time.sleep(1)
sys.stdout.write(`10-second` + " seconds \r")
sys.stdout.flush()
Jul 18 '05 #6
Great, thanks for all help! I'll try these things

"Derek" <no**@none.com> wrote in message
news:bu************@ID-46268.news.uni-berlin.de...
"Diez B. Roggisch" wrote
Any alternatives to ncurses? It seems like a overkill for this...


Maybe you can use sys.stdout.write in conjunction with control-
codes for moving back the cursor to column one. But you'll have
to lookup these for yourself :)


I think \r is the control code (at least if you want to go back to the
start of the line):

import time, sys
for second in range(10):
time.sleep(1)
sys.stdout.write(`10-second` + " seconds \r")
sys.stdout.flush()
--
http://mail.python.org/mailman/listinfo/python-list



Jul 18 '05 #7
The cheesy dirt simple way:

print "Closing window in :"
for second in range(10):
time.sleep(1)
#print enough spaces to cover up the last message.
print " "*20 + "\r",
print `10-second` +" seconds",

Note the comma at the end of each print statement.
That causes python not to output a newline.

HTH

Sam Walters.

--
Never forget the halloween documents.
http://www.opensource.org/halloween/
""" Where will Microsoft try to drag you today?
Do you really want to go there?"""

Jul 18 '05 #8
Samuel Walters fed this fish to the penguins on Wednesday 14 January
2004 21:30 pm:
print " "*20 + "\r",
print `10-second` +" seconds",

Note the comma at the end of each print statement.
That causes python not to output a newline.
Don't you need a \r on the second print line also? Otherwise the
spaces will be printed at the end of the previous counter value?
Though would \r even work if this was to be run on a Mac -- I thought
Macs used to use \r for line ending (maybe OS-X has gone to \n).
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #9
| Dennis Lee Bieber said |
Don't you need a \r on the second print line also? Otherwise the
spaces will be printed at the end of the previous counter value?
Um, yeah. You do.


Though would \r even work if this was to be run on a Mac -- I
thought
Macs used to use \r for line ending (maybe OS-X has gone to \n).


I don't know. I've never owned a mac, and haven't ever worked on one.
Thus, mac nuances rarely enter my mind even when I know about them.

Sam Walters.

--
Never forget the halloween documents.
http://www.opensource.org/halloween/
""" Where will Microsoft try to drag you today?
Do you really want to go there?"""

Jul 18 '05 #10
Samuel Walters fed this fish to the penguins on Thursday 15 January
2004 17:23 pm:


I don't know. I've never owned a mac, and haven't ever worked on one.
Thus, mac nuances rarely enter my mind even when I know about them.
While I don't know about OS-X (being a BSD/Mach core?), I'm sure the
earlier versions used <CR> (\r) for line endings (I think the TRS-80
did too). The Amiga used <LF> (\n)... And of course, you get the
confusion in Windows of <CR><LF> (but not <LF><CR>!)
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #11
"Totte Karlsson" <mt*@qm.com> writes:
Any alternatives to ncurses? It seems like a overkill for this...

import sys, time
nrchars = 0

for i in xrange(10):
sys.stdout.write("\b \b"*nrchars)
sys.stdout.flush()
Str = "%i seconds to go" % (10-i)
nrchars = len(Str)
sys.stdout.write(Str)
sys.stdout.flush()
time.sleep(1)
print
--
Valentino Volonghi, Regia SpA, Milan
Linux User #310274, Gentoo Proud User
Jul 18 '05 #12

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

Similar topics

8
by: Totte Karlsson | last post by:
Hi, How can I print to the console without having it scrolling to a new line for each print statement? I want to print a count down in the console, but for each count it scrolls the screen (of...
0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
0
by: Programatix | last post by:
Hi, I am working on the PrintDocument, PrintDialog, PageSetupDialog and PrintPreviewControl components of Visual Studio .NET 2003. My developement machine is running Windows XP. There are...
0
by: Alex Moskalyuk | last post by:
I am using System.Windows.Forms.TextBox to publish some real-time data that's coming off the external devices. My data is fed into the TextBox with proper precautions not to exceed the MaxSize...
2
by: PHead | last post by:
Is there any way to stop the console from scrolling? What I mean isnt to not scroll at all, its that I want to get rid of the buffer. When a new line is created, I want row 0 to go away...
4
by: Rob T | last post by:
I have a small VB program that has a printing module...very simple....and works great. However, If I try to print to a generic printer, I get the following error: "The data area passed to a...
1
by: kasargee | last post by:
In IE printing if scroll bar is moved to middle position and printing is done then print out are coming from scroll bar start position. But i want to print whatever seen on screen ,if scroll bar is...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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,...
0
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,...
0
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...
0
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,...

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.