Python Progress Bar由' tqdm'创建然后是每次迭代后的意外值/符号
我正在使用“ TQDM”软件包来建立进度栏。但是,在每次奇数的迭代(1,3,5)发生后,发生意外的值/数字(在这种情况下,当参数'ascii'等于true时,将出现数字5)。
Fortschritt: 17%|####5 | 1/6 [00:02<00:11, 2.20s/it]
Fortschritt: 33%|######### | 2/6 [00:07<00:14, 3.54s/it]
Fortschritt: 50%|#############5 | 3/6 [00:13<00:13, 4.65s/it]
该代码相对复杂,因此我不会在此处复制它们...如果有必要发现和解决问题,我将在此后减少并粘贴在这里。
任何帮助将不胜感激。 :)
----------代码补充--------------
from os import makedirs
from tqdm import tqdm
import time
Workflow = ['0','1', '2', '3', '4', '5', '6']
Probenliste = ['A','B']
Oligos= {'Oligo1':'Sequence1', 'Oligo2':'Sequence2'}
for schritt in tqdm(range(len(Workflow)-1), desc='Fortschritt', ascii=True, ncols=75):
schritt_name = Workflow[schritt+1]
makedirs(schritt_name)
for n in range(len(Probenliste)):
probe = Probenliste[n]
for primer_name, sequence in Oligos.items():
time.sleep(1)
I am using 'tqdm' package to establish a progress bar. However, after every iteration of odd numbers (1,3,5) an unexpected value/number occurs (in this case number 5 appears when argument 'ascii' is equal to True).
Fortschritt: 17%|####5 | 1/6 [00:02<00:11, 2.20s/it]
Fortschritt: 33%|######### | 2/6 [00:07<00:14, 3.54s/it]
Fortschritt: 50%|#############5 | 3/6 [00:13<00:13, 4.65s/it]
The code is relative complex so I would not copy them here... if it is necessary for finding out and solving the problem, I will reduce it and paste here afterwards.
any help will be appreciated. :)
---------code supplemented----------
from os import makedirs
from tqdm import tqdm
import time
Workflow = ['0','1', '2', '3', '4', '5', '6']
Probenliste = ['A','B']
Oligos= {'Oligo1':'Sequence1', 'Oligo2':'Sequence2'}
for schritt in tqdm(range(len(Workflow)-1), desc='Fortschritt', ascii=True, ncols=75):
schritt_name = Workflow[schritt+1]
makedirs(schritt_name)
for n in range(len(Probenliste)):
probe = Probenliste[n]
for primer_name, sequence in Oligos.items():
time.sleep(1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 [github]:tqdm/tqdm- documentation (是我的):
我在各种参数中播放了一点,我从经验上发现了这一点(我没有严格的解释),因为我没有足够的研究:
可以使用更简单的代码复制该行为。
code00.py :
output (尽管仅是最相关的最后一个,因为它不会捕获行为):
fix :
使用字符串 “#” (对于 ascii ),仅包含初始 char ( space )和最后一个( pound , # )。这样,就不会有任何可能的中间 char 。
According to [GitHub]: tqdm/tqdm - Documentation (emphasis is mine):
I played a bit with the various parameters, and I discovered this empirically (I don't have a rigorous explanation), as I didn't dive enough into the code:
The behavior can be reproduced using much simpler code.
code00.py:
Output (although only the final one which is not very relevant, as it doesn't capture the behavior):
The fix:
Use the string " #" (for ascii) which only contains the initial char (SPACE) and the final one (POUND, #). This way, there won't be any possible intermediate char.