14

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

top 4 comments
sorted by: hot top controversial new old
[-] henfredemars@infosec.pub 3 points 1 year ago

I'm disappointed that the article doesn't address why it's better than just using lambda.

[-] brettvitaz@programming.dev 1 points 1 year ago* (last edited 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 3 points 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 2 points 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.

load more comments
view more: next ›
this post was submitted on 07 Jul 2023
14 points (100.0% liked)

Python

6416 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS