tags:

views:

1128

answers:

4

Hello,

I am a noob when it comes to python. I have a python script which gives me output like this:

[last] ZVZX-W3vo9I: Downloading video webpage
[last] ZVZX-W3vo9I: Extracting video information
[download] Destination: myvideo.flv
[download]   9.9% of 10.09M at    3.30M/s ETA 00:02

The last line keeps getting updated with new values of progress. I want to change this. Instead of updating I want a new line to be printed each time. How can i do this? I think the part concerned is this bit:

def report_progress(self, percent_str, data_len_str, speed_str, eta_str):
    """Report download progress."""
    self.to_stdout(u'\r[download] %s of %s at %s ETA %s' %
     (percent_str, data_len_str, speed_str, eta_str), skip_eol=True)

If more code needs to be seen please let me know so that I can show you what is needed to solve this.

Thank you very much for any help.

+3  A: 

If I understand your request properly, you should be able to change that function to this:

def report_progress(self, percent_str, data_len_str, speed_str, eta_str):
    """Report download progress."""
    print u'[download] %s of %s at %s ETA %s' % (percent_str, data_len_str, speed_str, eta_str)

That will print the output on a new line each time.

mipadi
Thank you. Job done. :)
Abs
The \r then becomes redundant, mipadi. It was only used to return to the start of the line.
paxdiablo
+2  A: 

I'm thinking you may just need to change:

skip_eol=True

to:

skip_eol=False

and get rid of the "\r" to see what happens. I think you'll be pleasantly surprised :-)

paxdiablo
A: 

You can take out the \r, which moves to the cursor back to the beginning of the line and take out the skip_eol=True probably. Perhaps:

   self.to_stdout(u'[download] %s of %s at %s ETA %s' %
        (percent_str, data_len_str, speed_str, eta_str))
Emil
A: 

The "update" effect is achieved by '\r'.

Try this in a Python (2.x) shell:

print "00000000\r1111"

\r just returns the cursor to the beginning of the line.

Anonymous