Python 如何使用行大小更新TQM进度条?

Python 如何使用行大小更新TQM进度条?,python,tqdm,Python,Tqdm,我正试图在Python2.7(Ubuntu 16.04)中加载一个文件,并通过以下方式显示当前进度: 但它不起作用,预计到达时间太大了。有点像,但我正试图按照评论中所说的那样做。我发现密钥没有将file对象作为tqdm的“iterable”参数传递,而是手动管理更新: from tqdm import tqdm import os filename = '/home/nate/something.txt' with open(filename, 'r') as f: # unit='

我正试图在Python2.7(Ubuntu 16.04)中加载一个文件,并通过以下方式显示当前进度:


但它不起作用,预计到达时间太大了。有点像,但我正试图按照评论中所说的那样做。

我发现密钥没有将file对象作为tqdm的“iterable”参数传递,而是手动管理更新:

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))

我发现密钥没有将文件对象作为tqdm的“iterable”参数传递,而是手动管理更新:

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))

请注意,这仅适用于二进制文件。请注意,这仅适用于二进制文件。