Understanding Python: Click-based CLI

Поделиться
HTML-код
  • Опубликовано: 28 авг 2024
  • In this video, I go over how to create a command-line interface using the third-party library for Python called Click.
    Included in the lesson is how to use Click's decorators to add arguments and options for users of your script and how those arguments and options are handled in the function itself.
    As always, if you have any questions or suggestions for future videos, please leave a comment down below.
    Follow me on Twitter: / jakejcallahan
    Source: github.com/Jac...
    Timelapse music: 失望した by Eva
    Link: • EVA - 失望した [Synthwave]...
    Outro music: Elix by Synthness
    Link: • Synthness - Elix ★ No ...

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

  • @ingydegmar2060
    @ingydegmar2060 Год назад

    I swear, at this rate we'll have a 3 line pizza builder app in a couple more videos.
    Thanks man.

    • @JakeCallahan
      @JakeCallahan  Год назад

      Haha don't you dare make that my new life goal!

  • @turugasairam2886
    @turugasairam2886 Год назад

    Amazing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.. The way you explained is truly amazing. Subscribed right away.....

  • @vickylance
    @vickylance 2 года назад +1

    Subscribed immediately when u explained their decorators rather than just going over the functions. Looking at your subscribers count u are underrated. Maybe make some fancy thumbnails going forward to make people click.

    • @JakeCallahan
      @JakeCallahan  2 года назад +1

      Thanks, I'm sure it doesn't help that I'm not very consistent! Hopefully I'll get time to put out more videos once things calm down.

  • @hoox2795
    @hoox2795 2 года назад

    No doubt I have gained a lot , provides a lot of details,unlike the anothers,not only talk about how to code but also talk why code.especially use ipython to find the diffrent between a to b,i do not know the way that before this!very great!

  • @rob_mccormack
    @rob_mccormack Год назад +1

    Excellent! Well done, should be >100,00 views...
    thanks.

  • @Diachron
    @Diachron 2 года назад

    Underrated video. Good coverage.

  • @cheesecake_mafia
    @cheesecake_mafia 27 дней назад

    Another great tutorial! Awesome work Jake.
    I just thought it's a bit uncomfortable to write -t in front of every topping we want to pass, and hence searched the documentation. Unfortunately, click by default has no help for passing multiple args while writing the option name only once. But I think a custom class/function and some clever str manipulation can do the trick. Other than that, I feel click is a great tool for every python programmer to have.
    Do you have some custom class to handle such scenarios? I think it'll relatively easy to build one. I am guessing we could even use a namedtuple object for this.
    Cheers and Kudos!

    • @JakeCallahan
      @JakeCallahan  26 дней назад

      One of the easiest ways to solve this problem is just to make your users specify multiple items in a comma separated list.
      --toppings cheese,bacon,onion
      Then you just split that string on the commas and handle the individual values.

  • @jonas7438
    @jonas7438 2 года назад +1

    Another great video of yours!

  • @arturocdb
    @arturocdb 2 года назад +1

    Great video, thank you so much…, just for info, if you can do a video about python fire, its much better and easy than click

    • @JakeCallahan
      @JakeCallahan  2 года назад

      Interesting. I don't know if I've heard of that library. What makes it easier than click?

    • @arturocdb
      @arturocdb 2 года назад

      @@JakeCallahan team that develop that tool comes from google, officialy its a google tool, its much easy than because not use decorator, all that job its made internally by fire.., there is a video made from david bieber -> the creator that explain it.

    • @JakeCallahan
      @JakeCallahan  2 года назад

      I don't place much weight on what company is behind a tool, but you recommended it, so I will check it out. Thanks!

    • @arturocdb
      @arturocdb 2 года назад

      @@JakeCallahan ruclips.net/video/qmptPeLVJbI/видео.html

  • @rob_mccormack
    @rob_mccormack Год назад

    I added this to cause help to show if no arguments
    @click.command(no_args_is_help=True) #cause help to run help
    which I think would be the preferred behavior.

  • @Matt-dk3wl
    @Matt-dk3wl 2 года назад

    Maybe I'm missing something but your help says the syntax is
    pizza_builder.py [OPTIONS] [s|m|l] etc... but you are throwing your options AFTER... so your help string is wrong... right?
    I would expect your syntax to be
    pizza_builder.py -t onions s thin
    I'm probably missing something but I think there's too much magic going on with Click. I prefer argparse.

    • @Matt-dk3wl
      @Matt-dk3wl 2 года назад +1

      Replying to myself after getting your code from github. Yeah, the help string is wrong. Excellent video BTW, it really helped me understand Click a bit more... Still too much magic for me. Python was SUPPOSED to be the "One, and only one clear and obvious way to do something"... It was its super power against Perl. Well not anymore. Python's in Perl's boat now.

    • @JakeCallahan
      @JakeCallahan  2 года назад +1

      You should be able to pass options before or after arguments. My personal preference is after so that's what you'll see me using more often than not.
      Python has certainly seen feature creep quite a bit, which (for better or worse) is hard to avoid.
      Thanks for watching and the conversation!