An exploration of partial() and partialmethod() in functools

    • brettvitaz@programming.dev
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      1 year ago

      I’m disappointed

      Why? It’s not better or worse, just different. Lambdas have their use case, as does function partials and wraps.

      • Spott@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        1 year ago

        They are different though, and the article doesn’t go into why they are different, which I think is a major omission (though a common one in articles about this subject).

        The difference is that lambda functions are late binding, while partial functions are bound when they are created. This can lead to all sorts of hard to find bugs when using lambdas that are avoided by using partials.

  • Zeusbottom@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    My favorite usage of partial() is when I’m print()ing to a file. So helpful to keep the code readable and easy to change.