【问题标题】:How to add progress bar in a code with library functions? [duplicate]如何在带有库函数的代码中添加进度条? [复制]
【发布时间】:2021-11-03 21:03:49
【问题描述】:

如何用库函数显示代码的执行进度?

import networkx as nx
graph=nx.erdos_renyi_graph(100000,.2)

visited = set() # Set to keep track of visited nodes of graph.

def dfs(visited, graph, node):  #function for dfs 
    if node not in visited:
        print (node)
        visited.add(node)
        for neighbour in graph[node]:
            dfs(visited, graph, neighbour)

print("Following is the Depth-First Search")
dfs(visited, graph, '5000')
coms=nx.connected_components(graph)

【问题讨论】:

  • 你可以使用tqdm

标签: python


【解决方案1】:

如 cmets 中所述,使用 tqdm:

from tqdm import tqdm
for i in tqdm(range(10)):
  print(i, end = '')

输出:

100%|██████████| 10/10 [00:00<00:00, 26181.67it/s] 0123456789

【讨论】:

  • 嗨 Keivan,这类问题通常是重复的,请先搜索可能的重复项,然后在对该问题的评论中引用它们。而不是回答他们;重复项通常会很快关闭,因此您不会得到任何代表来回答它们。
  • 我应该在哪里使用这个代码?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-05
  • 1970-01-01
  • 1970-01-01
  • 2018-05-04
相关资源
最近更新 更多