This content originally appeared on Level Up Coding - Medium and was authored by Aravind Ramalingam
Let me explain with an example.

Introduction
Partial functions allow us to fix values for some arguments of a function and generate a new function. The common example for partial function would be:
This example is a solid starter example for partial functions, but feels more like a syntactic sugar rather than functionality gain. Partial function shines, when you are restricted by third party modules or code which you have no control over.
Example Brief
I was playing around with Matplotlib Animation module and found that save method has a progress callback function. Callback function takes two arguments (current_frame & total_frames), but a progress bar without metadata like file name and elapsed time is not very useful. So we will use Partial Function to enhance it.

Creating Animated Line Chart

Write to disk

Takeaway
Partial functions give you more control, especially when you are adding features on top of code written by others.
Resource
Customize or Extend Python Third-Party Modules Using Partial Function was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Aravind Ramalingam

Aravind Ramalingam | Sciencx (2021-07-10T22:13:02+00:00) Customize or Extend Python Third-Party Modules Using Partial Function. Retrieved from https://www.scien.cx/2021/07/10/customize-or-extend-python-third-party-modules-using-partial-function/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.