Printing a "status " line from a python script
clp at rebertia.com
Tue Nov 11 20:26:32 CET 2008
On Tue, Nov 11, 2008 at 11:02 AM, Chris Seymour <cgseymour at gmail.com> wrote:
> Hi All,
> I am working on a python script for my colleague that will walk a
> directory and search in the different files for a specific string.
> These pieces I am able to do. What my colleague wants is that when
> she runs the script the filename is replaced by the current file that
> is being processed. So instead of seeing a series of files being
> listed down the page, she only wants to see the file currently being
> I am not sure if this is even possible. Any thoughts would be greatly
Have you tried using carriage returns ("\r")?
chris ~ $ python
Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range(10):
... print '\r'+str(i),
Note how each line gets overwritten by the next so that we only see
the final number output (9).
But really, I don't see a good reason to do this. So what, the output
takes up some extra lines on the terminal? Big whoop. Your colleague
can either pipe the script to `less` or a file if it really bothers
them. And that way you get a list of all files processed, which can
often come in handy in my experience.
Follow the path of the Iguana...
More information about the Python-list