显示进度的脚本? [英] Script to show progress?

查看:49
本文介绍了显示进度的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 python 脚本处理一个大文件时,我想向用户显示进度.

I would like show progress to user when my python script processing a big file.

我看到脚本在 shell 中的同一光标位置打印 '\', "|', '/' 以显示进度.

I have seen script printings '\', "|', '/' in the same cursor position in the shell to show progress.

我如何在 python 中做到这一点?

How can I do that in python?

推荐答案

一个简单的infinite spinner"实现:

A simple "infinite spinner" implementation:

import time
import itertools

for c in itertools.cycle('/-\|'):
    print(c, end = '\r')
    time.sleep(0.2)

这篇关于显示进度的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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