tqdm:更新总数不重置时间已过

Edd*_*ker 2 python tqdm

我正在使用 tqdm 递归目录树。我不知道我将使用的路径数量,而且我不想在我做工作之前构建该列表只是为了获得准确的总数,我宁愿让它将进度条更新为它继续。

我发现我可以很好地使用 'reset(total=new_total)',但这也会重置时间。有没有办法可以保持时间,但只需将总数设置为新的东西?

Vis*_*hal 8

这是包reset内函数定义的定义tqdm

    def reset(self, total=None):
        """
        Resets to 0 iterations for repeated use.

        Consider combining with `leave=True`.

        Parameters
        ----------
        total  : int, optional. Total to use for the new bar.
        """
        self.last_print_n = self.n = 0
        self.last_print_t = self.start_t = self._time()
        if total is not None:
            self.total = total
        self.refresh()
Run Code Online (Sandbox Code Playgroud)

您需要的不是更新 的值self.last_print_tself.start_t而只是更新total

t.reset(total=new_total)您应该执行以下操作,而不是调用:

t.total = new_total
t.refresh()
Run Code Online (Sandbox Code Playgroud)