473,386 Members | 1,830 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,386 software developers and data experts.

command line reports

Is there a module somewhere that intelligently deals with reports to the
command line? I would like to report the progress of some pretty lengthy
simulations, and currently I have the new reports written on a new line
rather rather than overwriting the previous report.

Thanks,
Darren
Aug 11 '05 #1
6 1378
Darren Dale wrote:
Is there a module somewhere that intelligently deals with reports to the
command line? I would like to report the progress of some pretty lengthy
simulations, and currently I have the new reports written on a new line
rather rather than overwriting the previous report.


I'm afraid I don't understand this. Could you please give an example?

Of course, this is c.l.p., so I'm sure *someone* will understand it.
--
Michael Hoffman
Aug 11 '05 #2
Darren Dale wrote:
Is there a module somewhere that intelligently deals with reports to the
command line? I would like to report the progress of some pretty lengthy
simulations, and currently I have the new reports written on a new line
rather rather than overwriting the previous report.


You mean you want sys.stdout.write(report + '\r') instead of "print
report" ?

It's not really clear what you want. What's a "report" to you?

-Peter
Aug 11 '05 #3
Peter Hansen wrote:
Darren Dale wrote:
Is there a module somewhere that intelligently deals with reports to the
command line? I would like to report the progress of some pretty lengthy
simulations, and currently I have the new reports written on a new line
rather rather than overwriting the previous report.


You mean you want sys.stdout.write(report + '\r') instead of "print
report" ?

It's not really clear what you want. What's a "report" to you?

-Peter


I am printing something like

trial 1 of 100
trial 2 of 100
....

so I get 100 lines by the time the code is finished. I would like to replace
the previous report with the current one, so I only use one line by the
time the code is finished.

I was also hoping that there was a set of tools out there for spinners,
meters, etc...
Aug 11 '05 #4
On Thu, 11 Aug 2005 15:43:23 -0400, Darren Dale <dd**@cornell.edu> wrote:
Peter Hansen wrote:
Darren Dale wrote:
Is there a module somewhere that intelligently deals with reports to the
command line? I would like to report the progress of some pretty lengthy
simulations, and currently I have the new reports written on a new line
rather rather than overwriting the previous report.
You mean you want sys.stdout.write(report + '\r') instead of "print
report" ?

It's not really clear what you want. What's a "report" to you?

-Peter


I am printing something like

trial 1 of 100
trial 2 of 100
...

Peter's suggestion will work, but it's easy to get something like
import sys, time
def test(): ... for i in xrange(5):
... sys.stdout.write(('trial %s of 5'%(i+1)) + '\r')
... time.sleep(.25)
... print "We're done!"
... test()

We're done!5
^--(note leftover from last "report: line)
By the same token (more or less ;-) if your "report" line shortens
during progress (e.g., changing from

'long_name_test trial 100 of 100'

to

'short_name trial 1 of 10'

you will likely see

'short_name trial n of 10 of 100'

for a while, unless you pad the report line with blanks to a constant length.

Also, I guess some platforms could require flushing stdout to be sure of
seeing the latest line as you go.

so I get 100 lines by the time the code is finished. I would like to replace
the previous report with the current one, so I only use one line by the
time the code is finished.

I was also hoping that there was a set of tools out there for spinners,
meters, etc...

The question with python for this kind of thing is usually, "Which will be
faster, googling for it, or writing it?" ;-)

Regards,
Bengt Richter
Aug 11 '05 #5
Bengt Richter wrote:
On Thu, 11 Aug 2005 15:43:23 -0400, Darren Dale <dd**@cornell.edu> wrote:
Peter Hansen wrote:
Darren Dale wrote:
Is there a module somewhere that intelligently deals with reports to
the command line? I would like to report the progress of some pretty
lengthy simulations, and currently I have the new reports written on a
new line rather rather than overwriting the previous report.

You mean you want sys.stdout.write(report + '\r') instead of "print
report" ?

It's not really clear what you want. What's a "report" to you?

-Peter


I am printing something like

trial 1 of 100
trial 2 of 100
...

Peter's suggestion will work, but it's easy to get something like
>>> import sys, time
>>> def test(): ... for i in xrange(5):
... sys.stdout.write(('trial %s of 5'%(i+1)) + '\r')
... time.sleep(.25)
... print "We're done!"
... >>> test()

We're done!


Thanks, I didnt realize that \r is different from \n.
Aug 11 '05 #6
Darren Dale wrote:
Thanks, I didnt realize that \r is different from \n.


\r has is a byte with value 13, which is the Carriage Return (CR)
control character in ASCII. \n has value 10 and is the Line Feed (LF)
character. CR is named after the old teletypewriter operation involving
moving the "carriage" back to one edge to restart typing text. It
wasn't very useful without also moving to a new line (unless you wanted
to cut your paper by repeatedly printing a line of hyphens), which is
what LF was used for -- like rotating the platen (I think that's the
word) on a typewriter up one line. Hitting the arm on a typewriter is
like a CR plus a LF together, and this is immortalized in the CR/LF
combination required still under Microsoft's most advanced operating
systems, long after it's no longer necessary to have the two distinct
characters. (<sigh>)

Most operating systems have adopted the combined behaviour (go to start
of line, move down one line) together under the LF character, since
ASCII doesn't have a single "new line" character (though VT or Vertical
Tab has been proposed for that since it has no other practical use these
days). The CR character still generally does the "go to start of line"
operation when used in the console, so it's pretty handy to "overwrite
the previous line" as you wanted to. In rare situations, such as
terminal software like Hyperterm, LF doesn't necessarily take you back
to the start of a line but merely moves you down a single line at the
same column position, much like its original/intended behaviour.

-waxing-historically-and-97-percent-accurately y'rs,
Peter
Aug 12 '05 #7

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

Similar topics

0
by: David Merrill | last post by:
How do I embed an rpt file into my exe using command line tools? VS.Net does this behind the scenes, however, I cannot install VS.Net 2003 on our build machine because it must be NT4. So how do...
0
by: Mukesh Kumar | last post by:
hi all, I have created some independent reports through crystal reports developer edition v 10 and developed a small tool in .net framework v 1.1 to view these reports through the crystal reports...
21
by: Colleyville Alan | last post by:
I am now using the Execute command to run SQL for action queries. When I had them as saved queries, I would use DoCmd.SetWarnings False to allow the queries to overwrite existing tables. when I...
1
by: Dennis Gaida | last post by:
Hi there, I want to upload some exported reports to a FTP Server, for this I use a command line FTP utility. My Database sits in C:\Documents and Settings\Dennis\My Documents\Database The FTP...
1
by: xtra | last post by:
Hi Folk I have written a module that allows you to type a bunch of commands in the immediate window, for quick access to information when you are creating VB code. Here it is, it may be helpful...
4
by: kwatch | last post by:
Hi, I have a question about os.times(). os.times() returns a tuple containing user time and system time, but it is not matched to the result of 'time' command. For example, os.times() reports...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
2
code green
by: code green | last post by:
What is the best command line equivalent of $_SERVER. I have recently written a number of scripts to run from an intranet that generate reports written to CSV and XLS files that can be downloaded....
16
by: Steve | last post by:
I am working on a database that has a main menu, many sub-menus and some sub-sub-menus. They are all forms that have numerous command buttons on them to open forms and reports in the database. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.