2 Ways to Add a Progress Bar in Python - tqdm and alive-progress

Поделиться
HTML-код
  • Опубликовано: 10 окт 2024

Комментарии • 3

  • @Cod1ngTogether
    @Cod1ngTogether  День назад +1

    Thanks for watching! Does this help you? Did you like it?
    Would you like to see how to use this progress bar in a real-life function, such as unzipping a file and transferring the files? Let me know!

  • @aonodensetsu
    @aonodensetsu День назад +2

    one downside to this video, it didn't even cover the simplest (and best) use of tqdm - wrapping an iterator
    for item in tqdm(qs):
    tqdm can infer the length of most iterators, and if it can't it will stil show the amount of work already done

    • @Cod1ngTogether
      @Cod1ngTogether  День назад

      I get your point, and you're definitely right to some extent!
      It would have been simpler, with less code, and so on.
      qs = [1, 2, 3, 4, 5, 6, 7]
      for item in tqdm(qs, desc="progress bar", ascii="░X█", ncols=700):
      # Add processing/work here
      time.sleep(0.5)
      In this example, though, it's just harder to explain-for instance, when the .update() of the progress bar happens and how it works in general. That's why I decided to use the method I did. But hopefully, a lot of people will see your comment and learn from this approach too.