[英]Using tqdm progress bar on a function call
有沒有辦法在 function 調用上使用 tqdm,因為我不知道如何顯示進度條,因為我沒有任何循環:這是 function 調用發生的地方:
if length == 2:
post().request(email,password)
每次它發出請求時,我都希望我的進度條移動,有沒有辦法?
所以帖子是 class。 據我了解你的問題,你可以試試這些:
對於每個請求的進度條:
class post():
def __init__(self):
pass
def req(self):
for _ in trange(1):
print("req")
p = post()
p.req()
對於 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)
(我不確定為什么沒有格式它就不能工作。可能是因為 python 對象或回調with
c++ 對象的工作方式不同。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.