说到python,我是菜鸟。我有一个 python 脚本,它给我这样的输出:
[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
最后一行不断更新新的进度值。我想改变这个。我不想更新,而是希望每次都打印一个新行。我怎样才能做到这一点?我认为有关的部分是:
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)
如果需要查看更多代码,请告诉我,以便我可以向您展示解决此问题所需的内容。
非常感谢您的帮助。
最佳答案
如果我正确理解了您的要求,您应该能够将该功能更改为:
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)
每次都会在新行打印输出。
关于Python 脚本 : Print new line each time to shell rather than update existing line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/529395/