读取文件时,Python enumerate() tqdm 进度条?

编程入门 行业动态 更新时间:2024-10-27 17:10:10
本文介绍了读取文件时,Python enumerate() tqdm 进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我使用此代码迭代我打开的文件时,我看不到 tqdm 进度条:

I can't see the tqdm progress bar when I use this code to iterate my opened file:

with open(file_path, 'r') as f: for i, line in enumerate(tqdm(f)): if i >= start and i <= end: print("line #: %s" % i) for i in tqdm(range(0, line_size, batch_size)): # pause if find a file naed pause at the currend dir re_batch = {} for j in range(batch_size): re_batch[j] = re.search(line, last_span)

在这里使用 tqdm 的正确方法是什么?

what's the right way to use tqdm here?

推荐答案

您走对了.您正在正确使用 tqdm,但在使用 tqdm 时停止打印循环内的每一行.您还需要在第一个 for 循环而不是其他循环中使用 tqdm,如下所示:

You're on the right track. You're using tqdm correctly, but stop short of printing each line inside the loop when using tqdm. You'll also want to use tqdm on your first for loop and not on others, like so:

with open(file_path, 'r') as f: for i, line in enumerate(tqdm(f)): if i >= start and i <= end: for i in range(0, line_size, batch_size): # pause if find a file naed pause at the currend dir re_batch = {} for j in range(batch_size): re_batch[j] = re.search(line, last_span)

关于使用 enumerate 的一些注意事项及其在 tqdm 中的用法 此处.

Some notes on using enumerate and its usage in tqdm here.

更多推荐

读取文件时,Python enumerate() tqdm 进度条?

本文发布于:2023-11-23 09:49:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621002.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进度条   文件   enumerate   Python   tqdm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!