[英]How do I update a tqdm progress bar with line size?
我正在尝试在Python2.7(Ubuntu 16.04)中加载文件,并使用tqdm显示当前进度:
from tqdm import tqdm
import os
with open(filename, 'r') as f:
vectors = {}
tq = tqdm(f, total=os.path.getsize(filename))
for line in tq:
vals = line.rstrip().split(' ')
vectors[vals[0]] = np.array([float(x) for x in vals[1:]])
tq.update(len(line))
但是它无法正常工作,因为ETA太大了。 这个示例有点类似,但是我正按照注释中的说明进行操作。
我发现密钥没有将文件对象作为tqdm的“可迭代”参数传递,而是手动管理更新:
from tqdm import tqdm
import os
filename = '/home/nate/something.txt'
with open(filename, 'r') as f:
# unit='B' and unit_scale just prettifies the bar a bit
tq = tqdm(total=os.path.getsize(filename), unit='B', unit_scale=True)
for line in f:
tq.update(len(line))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.