[英]Using tqdm progress bar on a function call
Is there a way to use tqdm on a function call because i am not understanding how to display a progress bar because i don't have any loops: this is where the function call happens:有没有办法在 function 调用上使用 tqdm,因为我不知道如何显示进度条,因为我没有任何循环:这是 function 调用发生的地方:
if length == 2:
post().request(email,password)
everytime it makes a request, i want my progress bar to move, is there a way?每次它发出请求时,我都希望我的进度条移动,有没有办法?
So post is a class.所以帖子是 class。 As much I understood your question, you may try these:
据我了解你的问题,你可以试试这些:
For a progressbar for each request:对于每个请求的进度条:
class post():
def __init__(self):
pass
def req(self):
for _ in trange(1):
print("req")
p = post()
p.req()
For single progressbar for n_req requests:对于 n_req 请求的单个进度条:
class post(tqdm.tqdm):
def __init__(self, n_req = 1):
tqdm.tqdm.__init__(self)
self.total = n_req
def req(self, i):
print("req", i)
self.update()
n_req = 5
with post(n_req) as p:
for i in range(n_req):
p.req(i)
#------------OR-----------------
n_req = 5
with post(n_req) as p:
p.req(1); p.req(2); p.req(3); p.req(4); p.req(5)
(I'm not sure why it's not working without with
format. Probably because python objects or callbacks don't work same as c++ objects.) (我不确定为什么没有格式它就不能工作。可能是因为 python 对象或回调
with
c++ 对象的工作方式不同。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.