python try except and best practices (beginner - intermediate) anthony explains

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

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

  • @МаркКазино
    @МаркКазино 3 года назад +7

    I love how his haircut evolves through the episodes, as well as my knowledge after watching them! Keep it up, very enlightening :)

  • @Jakub1989YTb
    @Jakub1989YTb 3 года назад +12

    Personally I prefer: try-except-else-finally
    over: try-except-finally-else
    Having the finally at the end makes imho more sense. Since it runs after else.

    • @anthonywritescode
      @anthonywritescode  3 года назад +12

      actually looks like there's a mistake in the video then -- finally has to come after `else` otherwise it's a syntax error

  • @pradhvanbisht2177
    @pradhvanbisht2177 3 года назад +6

    I am so grateful to all the Anthony explains videos that I get to see all of them early in my career. Would have taken me some time to learn a lot of the concepts on my own.

  • @Jakub1989YTb
    @Jakub1989YTb 3 года назад +3

    When talking about exceptions, I would also mention, what return statement in the various blocks does.
    For me it was confusing at the beginning, so maybe it would help others.
    For example:
    try:
    foo()
    return a
    except:
    ...
    else:
    return b
    finally:
    return c

    • @Jakub1989YTb
      @Jakub1989YTb 3 года назад

      It is "stupid" example to have that many returns, but somebody may find the behavior of this snippet suprising.

  • @marsma18
    @marsma18 3 года назад +3

    Nice compeehensive guide to exceptions. Thanks. It is good reminder for all of that thing.

  • @jrib
    @jrib 3 года назад +2

    good one! prob worth noting not all try-except languages (e.g. JS) have the else case.

  • @AceofSpades5757
    @AceofSpades5757 3 года назад +3

    That was great. I felt pretty confident in my exception handling, but that was very informative.

  • @apexyu164
    @apexyu164 3 года назад +4

    can you also demonstrate
    1) Nested Try /Except
    2) A try except inside a while-loop ,for example, i have 10 id need to update or do whoever from the db , and any one of the action is fail, do you show a guide on this?
    thanks

    • @anthonywritescode
      @anthonywritescode  3 года назад +1

      (1) you probably shouldn't
      (2) there's nothing special beyond what I showed here

  • @joshsnyder5882
    @joshsnyder5882 3 года назад +1

    Do you have any thoughts to share on `raise...from...`?

    • @anthonywritescode
      @anthonywritescode  3 года назад +1

      yep! I go over that in the linked video in the description -- though most of the time I don't bother personally

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

    You're a great teacher, thank you! 😃

  • @sotirigeorgiou3205
    @sotirigeorgiou3205 3 года назад +1

    I've never seen a keyboard in half.. but somehow it looks more practical haha

  • @ericng8807
    @ericng8807 3 года назад +2

    not me writing large try blocks 👀

  • @lonterel4704
    @lonterel4704 3 года назад +1

    Hi, explain pls variadic generics (pep646) in py310

    • @anthonywritescode
      @anthonywritescode  3 года назад +1

      variadic generics are still in the draft stage and did not make it into python 3.10 (if they land they'll be in 3.11 and I'll explain them when there's a stable implementation and type-checker support!)

    • @lonterel4704
      @lonterel4704 3 года назад

      @@anthonywritescode what do you think about +1 another syntax in python?

    • @anthonywritescode
      @anthonywritescode  3 года назад +1

      I think match and walrus are bad, splat-getitem seems not really that problematic relatively speaking

    • @lonterel4704
      @lonterel4704 3 года назад

      @@anthonywritescode splat-getitem? Sry, dont understand

    • @anthonywritescode
      @anthonywritescode  3 года назад +1

      the new syntax proposed in 646

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

    Thank you

  • @aikimark1955
    @aikimark1955 3 года назад

    I can't read what you're typing

    • @anthonywritescode
      @anthonywritescode  3 года назад

      how small is your screen? the font size is very large

    • @aikimark1955
      @aikimark1955 3 года назад

      @@anthonywritescode 22" (1280x800 resolution). Watching in 720p.
      Half your screen is wasted by a second, unused, window.

    • @davititchanturia
      @davititchanturia 3 года назад +4

      for me its is perfect

    • @anthonywritescode
      @anthonywritescode  3 года назад +2

      the second screen is used by running commands

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

      Im watching on an 11“ iPad and I can see everything, I guess it’s your resolution that is very low