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

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ต.ค. 2024

ความคิดเห็น • 7

  • @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  วันที่ผ่านมา +1

      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.

    • @aonodensetsu
      @aonodensetsu ชั่วโมงที่ผ่านมา +1

      @@Cod1ngTogether with statements are good to know as well, and explicitly calling update is a clearer way, but you also don't manually increment indexes in python, instead using "for i in list:" which is the same concept, rather than
      i = 0
      while True:
      if i >= len(qs):
      break
      item = qs[i]
      # do things
      i += 1
      most concepts can be reduced, but python is a highly abstract language and abstract constructs for quality of life are highly important

    • @Cod1ngTogether
      @Cod1ngTogether  38 นาทีที่ผ่านมา

      @aonodensetsu i fully agree to your words. 👍🏻😄 and thank you for this discussion. Most of the time it just depends on your knowledge/ experience how efficient you can use python.
      Here is a older video from me:
      How to transpose a matrix with LIST COMPREHENSION #python #programming #coding
      th-cam.com/users/shortsnzE5cpFfSi8?feature=share
      Its possible in python, but i never would code like this in real projects because its hard to read if you use it barely 😄

  • @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!

  • @tomvondeek
    @tomvondeek 7 ชั่วโมงที่ผ่านมา +1

    i remember i school project back in something like 1996 or something, very first introduction in school to turbo pascal delphi. during that schoolyear we learned basic programming stuff and as a final had to program a hangman game, something like that. i wrote a progressbar loadingscreen. the progressbar itself was randomised to a total of 7.5 seconds, but how it got from start to end was random every time starting the code, i thought it was funny back then

    • @Cod1ngTogether
      @Cod1ngTogether  55 นาทีที่ผ่านมา

      Hahah sounds like a fun idea 😂