如何在控制台的同一位置写入输出? [英] How do I write output in same place on the console?

查看:112
本文介绍了如何在控制台的同一位置写入输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,正在编写一些脚本来自动从FTP服务器等下载文件.我想显示下载进度,但希望它保持不变,例如:

I am new to python and am writing some scripts to automate downloading files from FTP servers, etc. I want to show the progress of the download, but I want it to stay in the same position, such as:

输出:

正在下载文件FooFile.txt [47%]

Downloading File FooFile.txt [47%]

我正试图避免这样的事情:

I'm trying to avoid something like this:

     Downloading File FooFile.txt [47%]
     Downloading File FooFile.txt [48%]
     Downloading File FooFile.txt [49%]

我应该怎么做?

重复:推荐答案

您还可以使用回车符:

sys.stdout.write("Download progress: %d%%   \r" % (progress) )
sys.stdout.flush()

这篇关于如何在控制台的同一位置写入输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆