Python 脚本 : Print new line each time to shell rather than update existing line

标签 python shell

说到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/

相关文章:

python - 如何将这 2 个日期/时间列转换为 1 个?

python - 如何打印出 Python 函数需要/允许哪些参数?

python - PyTorch next(iter(training_loader)) 极慢,简单的数据,num_workers 不行吗?

linux - 脚本中 ps aux 和 `ps aux` 之间的不同结果

python - 终端中的嵌套 For 循环

shell - 使用 awk、sed 修剪前 9 个字母

linux - 为什么 bash 在不同风格的 linux/unix 中看起来不同?

python - 导入错误: No module named zlib; tox

python - 在类方法内部定义时,信息级别日志记录消息不会在 Debug模式下打印

shell - Elastic Beanstalk cron 和部署权限