On Feb 25, 1:52 pm, Marco Streng <marco.str...@gmail.com> wrote:
> I'm doing a long computation in Sage and I'd like to be able to print
> some status information to the screen, such as the number of database
> entries that I have tested, or the total time spent on different parts
> of an algorithm.
>
> If I use the print command, then such information will accumulate and
> make it impossible to scroll back to the rest of my terminal session,
> or if I use a notebook, it makes the notebook very untidy and long.
>
> Is there an easy way to either remove something that I have 'print'-ed
> before, or (in a notebook) to create some sort of text box in which I
> can let my code add and remove text?

I don't know about the notebook, but in a terminal you can use the
'\r' (carriage return) character to jump to the beginning of the line:

sage: print 'abcd\refg'
efgd

Not that this just overwrites what was there before, so extra
characters can be leftover if you don't fill the line with spaces
(e.g. the 'd' above).  This probably isn't a problem though, as I
suspect you intend something like this:

sage: for i in range(0, 100, 10):
....:     print '%s%% complete.\r' % i,
....:     sys.stdout.flush()
....:     sleep(0.5)

Note the , (comma) at the end of the print line, which suppresses
printing the newline (and turns off flushing, unfortunately).

Hope this helps,
Hamish.

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to