473,811 Members | 3,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
8 11775
"Totte Karlsson" <mt*@qm.com> writes:
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


You need to flush after the print statements. If you have several
prints (not just 1 as in this example), it is easier to hide in a
separate function.

def msg(txt):
sys.stdout.writ e(txt)
sys.stdout.flus h()
for second in range(10):
time.sleep(1)
msg(`10-second` +" seconds ") #add a space at the end to delimit
print #to finish off the line

--
ha************@ boeing.com
6-6M31 Knowledge Management
Phone: (425) 342-5601
Jul 18 '05 #2
>

"Totte Karlsson" <mt*@qm.com> writes:
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 some code i got off the web.
I use it on my os2 2.1 laptop for which I don't have curses or tkinker libs.
I mostly use the color functions and move
as a analog to turbo pascal/basic gotoxy.

# begin code

#!/usr/bin/env python
'''
ansi.py

ANSI Terminal Interface

(C)opyright 2000 Jason Petrone <jp@demonseed.n et>
All Rights Reserved

Color Usage:
print RED + 'this is red' + RESET
print BOLD + GREEN + WHITEBG + 'this is bold green on white' + RESET

Commands:
def move(new_x, new_y): 'Move cursor to new_x, new_y'
def moveUp(lines): 'Move cursor up # of lines'
def moveDown(lines) : 'Move cursor down # of lines'
def moveForward(cha rs): 'Move cursor forward # of chars'
def moveBack(chars) : 'Move cursor backward # of chars'
def save(): 'Saves cursor position'
def restore(): 'Restores cursor position'
def clear(): 'Clears screen and homes cursor'
def clrtoeol(): 'Clears screen to end of line'
'''

############### ############### ##
# C O L O R C O N S T A N T S #
############### ############### ##
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
WHITE = '\033[37m'

RESET = '\033[0;0m'
BOLD = '\033[1m'
REVERSE = '\033[2m'

BLACKBG = '\033[40m'
REDBG = '\033[41m'
GREENBG = '\033[42m'
YELLOWBG = '\033[43m'
BLUEBG = '\033[44m'
MAGENTABG = '\033[45m'
CYANBG = '\033[46m'
WHITEBG = '\033[47m'

def move(new_x, new_y):
'Move cursor to new_x, new_y'
print '\033[' + str(new_x) + ';' + str(new_y) + 'H'

def moveUp(lines):
'Move cursor up # of lines'
print '\033[' + str(lines) + 'A'

def moveDown(lines) :
'Move cursor down # of lines'
print '\033[' + str(lines) + 'B'

def moveForward(cha rs):
'Move cursor forward # of chars'
print '\033[' + str(lines) + 'C'

def moveBack(chars) :
'Move cursor backward # of chars'
print '\033[' + str(lines) + 'D'

def save():
'Saves cursor position'
print '\033[s'

def restore():
'Restores cursor position'
print '\033[u'

def clear():
'Clears screen and homes cursor'
print '\033[2J'

def clrtoeol():
'Clears screen to end of line'
print '\033[K'

# ======end code=======

allen

Jul 18 '05 #3
Sorry for my post with all the ansi.py code.

I forgot the website I got it from.

Allen
Jul 18 '05 #4
Harry George <ha************ @boeing.com> wrote in message news:<xq******* ******@cola2.ca .boeing.com>...
"Totte Karlsson" <mt*@qm.com> writes:
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


You need to flush after the print statements. If you have several
prints (not just 1 as in this example), it is easier to hide in a
separate function.

def msg(txt):
sys.stdout.writ e(txt)
sys.stdout.flus h()
for second in range(10):
time.sleep(1)
msg(`10-second` +" seconds ") #add a space at the end to delimit
print #to finish off the line


That produces

10 seconds 9 seconds 8 seconds 7 seconds 6 seconds 5 seconds 4 seconds
3 seconds 2 seconds 1 seconds

This will produce a true countdown - the messages overwite each other:

for sec in range(10):
time.sleep(1)
m = "%2d seconds" % (10-sec)
msg(m + chr(13))

But this will only work on systems that properly handle control
characters. It works from a Windows command prompt but doesn't from
Idle which shows that silly undefined character box (which I'll
show here as []). So the Idle output looks like

10 seconds[] 9 seconds[] 8 seconds[] 7 seconds[] 6 seconds[]
5 seconds[] 4 seconds[] 3 seconds[] 2 seconds[] 1 seconds[]

which, when copied and pasted into Google, results in

10 seconds
9 seconds
8 seconds
7 seconds
6 seconds
5 seconds
4 seconds
3 seconds
2 seconds
1 seconds

This is the reason why the PROPER way to end a new line is
with a carriage_return + line_feed and not simply line_feed.
It also worked properly from the shell in Cygwin, but I
don't have a real unix or linux system to try it on.
Jul 18 '05 #5
PiedmontBiz wrote:

Sorry for my post with all the ansi.py code.

I forgot the website I got it from.


Google is your friend (along with five seconds of effort):

http://www.demonseed.net/~jp/code/ansi.py

-Peter
Jul 18 '05 #6
>From: Peter Hansen pe***@engcorp.c om
Date: 1/15/04 11:42 AM Eastern Standard Time
Message-id: <40************ ***@engcorp.com >

PiedmontBiz wrote:

Sorry for my post with all the ansi.py code.

I forgot the website I got it from.


Google is your friend (along with five seconds of effort):

http://www.demonseed.net/~jp/code/ansi.py

-Peter



Appreciate the rebuke. Also, the url was saved in the html by IExplorer. I
could have looked there.

Allen
Jul 18 '05 #7
"Totte Karlsson" <mt*@qm.com> wrote:

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"


print "Closing window in : "
for second in range(10,0,-1):
print "%2d\x08\x08\x0 8" % second,
time.sleep(1)

--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #8
> I use it on my os2 2.1 laptop for which I don't have curses or tkinker libs.

Do you also know how to get it to work on a Windows XP laptop? I
tried cmd.exe and command.com, but they don't so ansi.
Jul 18 '05 #9

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

Similar topics

11
5820
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 course). Is there another way? Here is the simple script for now
0
2303
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 some problems I encountered while using them. Please note that, the Regional and Language setting on my machine is using "Metric" measurement system (where the default is "US"). In this case, the measurement unit is "milimeters" and not "inches".
0
2131
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 some problems I encountered while using them. Please note that, the Regional and Language setting on my machine is using "Metric" measurement system (where the default is "US"). In this case, the measurement unit is "milimeters" and not "inches".
0
2655
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 limit. I use the AppendText() method of the TextBox class and tried playing with ScrollToCaret(), but that didn't seem to do anything different than normal behavior. I am getting the TextBox that supports auto-scrolling on some machines (i.e. the...
2
9872
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 permanently, not just be scrolled out of view. No scroll bars, etc. I know the C# console is weak, but even via Win32 API?
4
3178
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 system call is too small". I found the following article, that I assume is similar to my problem, which is of little help: http://support.microsoft.com/default.aspx?scid=kb;en-us;822779 Any suggestions?
1
1670
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 at middle position.
4
10519
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 doesn't seem to write to the screen in the way I would expect. The output is:
18
11322
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 classes, for each of the checked rows in the GridView. This works fine in the Visual Studio 2005 development environment on localhost. But, when I move the page to the web server, I get the error "Settings to access printer...
0
9724
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
10127
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
9201
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
7665
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
6882
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
5552
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...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
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
3863
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.