标签: tqdm

Python 的 ftplib 和 tq​​dm

我有一个控制台脚本,它使用ftplib作为后端从 ftp 服务器获取大量文件。我想使用tqdm为用户提供一些反馈,前提是他们打开了“详细”开关。这必须是可选的,因为某些用户可能会在没有tty访问权限的情况下使用脚本。

FTPLIBretrbinary方法采用了回调所以它应该有可能钩tqdm在那里莫名其妙。但是,我不知道这个回调会是什么样子。

python ftplib tqdm

5
推荐指数
1
解决办法
819
查看次数

使用Tqdm在下载文件时添加进度条

我一直在尝试使用 python 3.6 中的 Tqdm 模块设置进度条,但似乎我已经完成了一半。

我的代码如下:

from tqdm import tqdm
import requests
import time

url = 'http://alpha.chem.umb.edu/chemistry/ch115/Mridula/CHEM%20116/documents/chapter_20au.pdf'

# Streaming, so we can iterate over the response.
r = requests.get(url, stream=True)
#Using The Url as a filename
local_filename = url.split('/')[-1]
# Total size in bytes.
total_size = int(r.headers.get('content-length', 0))
#Printing Total size in Bytes
print(total_size)

#TQDM
with open(local_filename, 'wb') as f:
    for data in tqdm(r.iter_content(chunk_size = 512), total=total_size, unit='B', unit_scale=True):
        f.write(data)
Run Code Online (Sandbox Code Playgroud)

问题是,当我chunk_size = 512r.iter_content进度栏中插入时,在显示下载数据时根本不会加载,但是当我chunk_size = …

python download tqdm

5
推荐指数
1
解决办法
6142
查看次数

具有多个 tqdm 进度条的多处理

我正在并行处理多个大型 csv 文件。我希望每个文件都有一个进度条。

然而,虽然我显示了 5 个柱,但只有最后一个正在更新 - 似乎是所有进程同时更新的。由于我无法将整个 csv 文件读入内存,因此我使用文件大小来显示进度。

inputArg 是以数字结尾的文件夹路径。

def worker(inputArg):
        with open(inputArg + '/data.csv') as csvfile:
                size = os.path.getsize(inputArg + '/data.csv')
                text = "progresser #{}".format(inputArg[-1])
                pb = tqdm(total=size, unit="B", unit_scale=True, desc=text, position=int(inputArg[-1]))
                reader = csv.reader(csvfile, delimiter=',')
                for row in reader:
                        pb.update(len(row))
                        session.execute(*INSERT QUERY*)

    def scheduler(inputData):
            p = multiprocessing.Pool(multiprocessing.cpu_count()+1)
            p.map(worker, inputData)
            p.close()
            p.join()

    if __name__ == '__main__':
            folders = glob.glob('FILEPATH/*')
            print ('--------------------Insert started---------------')
            scheduler(folders)
            print('---------------------All Done---------------------')
Run Code Online (Sandbox Code Playgroud)

任何提示将不胜感激!

编辑:我确实检查了另一个答案,但我明确表示我想要多个进度条,而该答案只给你一个。因此,这不是重复的。

编辑2:这就是@bouteillebleu,我确实得到了我的酒吧,但由于某种原因只有最后一个被更新。 当前进度条

python csv python-multiprocessing tqdm

5
推荐指数
1
解决办法
7068
查看次数

jupyter笔记本同一行的进度条更新

我喜欢tqdm 进度条,因为它很简单。但我注意到,在某些情况下,进度条的每次更新都会打印在 jupyter 笔记本的新行中,如以下屏幕截图所示:

换行符中的 tqdm 进度更新

如何确保 tqdm 进度条的更新打印在 jupyter 笔记本的同一行中,如以下屏幕截图所示:

在此输入图像描述

python jupyter-notebook tqdm

5
推荐指数
1
解决办法
1703
查看次数

将 tqdm 与子流程结合使用

我正在尝试向我贡献的开源项目添加进度条功能。该软件以易于使用的方式将多线程命令传递给它。目前,我正在尝试向应用程序添加进度栏功能,但是无法让进度栏粘在底部并更新。

我们使用以下代码来处理命令:

subprocess.call(task, shell=True)
Run Code Online (Sandbox Code Playgroud)

我目前使用tqdm.update()更新栏的进度,但是它不断在新行上打印,使终端看起来很糟糕。 显示非粘性进度条的图像

要准确了解我们如何使用 tqdm 包,请参阅以下链接: https: //github.com/codingo/Interlace/blob/master/Interlace/lib/threader.py

最后,我们对该应用程序的目标是在终端底部粘贴一个进度条,这样它就不会影响输出并且看起来相当干净。任何帮助,将不胜感激!

python python-3.x tqdm

5
推荐指数
1
解决办法
4970
查看次数

无论终端窗口大小如何,如何让 tqdm 打印到同一行?

我正在使用 tqdm 绘制进度条,并且希望 tqdm 覆盖终端中的同一行,无论窗口大小如何。考虑以下代码:

from tqdm import trange
from time import sleep
t = trange(100, desc='Bar desc', leave=True)
for i in t:
    t.set_description("Bar desc (file %i)" % i)
    t.refresh() # to show immediately the update
    sleep(0.01)
Run Code Online (Sandbox Code Playgroud)

当我的终端窗口的宽度比 宽时"Bar desc (file %i)",tqdm 将根据我的需要打印进度条。但是,如果我减小终端窗口的宽度,tqdm 将打印为两行。每个 tqdm 更新都会打印到新行。即使我调整终端大小,有什么方法可以让 tqdm 打印到相同的两行吗?

我在 Ubuntu 中使用 bash 终端。

python bash tqdm

5
推荐指数
1
解决办法
1540
查看次数

将 tqdm 与多处理结合使用

我在 Python 3.7 中使用多处理来启动几个长时间运行的操作。每个单独的过程都需要几分钟才能完成。我想要同时显示正在运行的每个单独进程的进度条。我一直无法让它工作,因为进度条在我当前徒劳的尝试中不断跳跃并相互替换。

我这样创建我的流程:

with Pool(processes=cpu_count()) as pool:
    return pool.starmap(_execute_long_running_process, items)
Run Code Online (Sandbox Code Playgroud)

_execute_long_running_process我的函数内部有一个for循环,我希望进度条跟踪它。

for i in tqdm(list_of_things_to_process, leave=False):
    # do a thing
Run Code Online (Sandbox Code Playgroud)

我相信我的问题是由于每个tqdm进度条存在于与主流程分开的自己的流程中而产生的。我不确定有什么解决方法可以使它们按照我的预期运行,其中有几个进度条正在更新。

python multiprocessing tqdm

5
推荐指数
1
解决办法
6599
查看次数

Python3:如何将 set_description 与 tqdm.contrib.concurrent process_map 一起使用

我一直在使用 tqdm.contrib.concurrent 中的 process_map :https://tqdm.github.io/docs/contrib.concurrent/

如何设置进度条的描述,该进度条在每次迭代中都会发生变化?

我尝试过:(在这里删除了很多代码以简化它......)

from tqdm.contrib.concurrent import process_map 
import tqdm

def myfunc(htmlfile):

    tqdm.tqdm.set_description(htmlfile)

    ### function contents go here

r = process_map(myfunc, mylist, max_workers=16)
Run Code Online (Sandbox Code Playgroud)

但我得到AttributeError: 'str' object has no attribute 'desc'

是因为 process_map fromtqdm.contrib.concurrent不能与 set_description from 混合吗tqdm.tqdm

python parallel-processing tqdm

5
推荐指数
1
解决办法
1984
查看次数

如何设置 tqdm 的默认进度条颜色和背景颜色?

我在 Jupiter 笔记本中使用 tqdm。通常我会在白色背景上看到一个绿色进度条。但是,现在我看到粉红色背景上有一个黑色进度条:

import tqdm, tqdm.notebook
from time import sleep

# first progress bar
for i in tqdm.notebook.tqdm(range(10)):
    sleep(.1)

# second progress bar
for i in tqdm.notebook.tqdm(range(10)):
    sleep(.1)
    
# third progress bar
for i in tqdm.tqdm(range(10)):
    sleep(.1)
    
# fourth progress bar
for i in tqdm.tqdm(range(10), colour='green'):
    sleep(.1)
Run Code Online (Sandbox Code Playgroud)

产生这四个条:

在此输入图像描述

我想要的是一个绿色的进度条,没有粉红色的背景。

我安装 PyQt5 后出现了这种行为变化。我已经卸载了,但行为仍然存在。

另外,以前我tqdm.notebook.tqdm在笔记本中使用过进度条。现在该函数不显示进度条(条 1 和条 2)。我需要使用tqdm.tqdm(第 3 条和第 4 条)。

我认为问题与后端有关。

python progress-bar tqdm

5
推荐指数
1
解决办法
3108
查看次数

如何将tqdm与map用于Dataframes

我可以使用tqdm进度条和map函数来循环遍历数据帧/系列行吗?

具体而言,对于以下情况:

def example(x):
    x = x + 2
    return x

if __name__ == '__main__':
    dframe = pd.DataFrame([{'a':1, 'b': 1}, {'a':2, 'b': 2}, {'a':3, 'b': 3}])
    dframe['b'] = dframe['b'].map(example)
Run Code Online (Sandbox Code Playgroud)

python-3.x pandas tqdm

4
推荐指数
1
解决办法
1226
查看次数