

Samaksh Dubey August 28, 2026 Python Tips No comments
A decorator is a special function in Python that allows you to add extra functionality to another function without modifying its original code. Decorators are commonly used for logging, authentication, timing functions, and more.
In this post, we'll explore four common examples of decorators in Python.
Create a simple decorator that prints a message before calling a function.
def decorator(func):
def wrapper():
print("Before the function is called")
func()
return wrapper
@decorator
def greet():
print("Hello, World!")
greet()
Output
Before the function is calleddecorator() accepts a function as an argument.
wrapper() adds extra functionality before calling the original function.
@decorator applies the decorator to greet().
Calling greet() actually executes wrapper().
Decorators can also work with functions that take parameters.
def decorator(func): def wrapper(name): print("Welcome!") func(name) return wrapper @decorator def greet(name): print("Hello,", name) greet("Alice")
Output
Welcome!
Hello, Alice
wrapper(name) accepts the argument passed to greet().
It prints a welcome message before calling the original function.
The original function receives the same argument.
A decorator can execute code both before and after the original function.
def decorator(func):
def wrapper():
print("Starting...")
func()
print("Finished!")
return wrapper
@decorator
def task():
print("Task is running")
task()
Output
Starting...The decorator prints "Starting...".
It then calls the original function.
After the function finishes, it prints "Finished!".
This is useful for logging and monitoring function execution.
Use a decorator with a function that accepts user input.
def decorator(func):
def wrapper(name):
print("Welcome to Python!")
func(name)
return wrapper
@decorator
def greet(name):
print("Hello,", name)
name = input("Enter your name: ")
greet(name)
Sample Input
SamOutput
Welcome to Python!The user enters a name.
The decorator displays a welcome message.
The original function greets the user using the entered name.
| Method | Best For |
|---|---|
| Basic Decorator | Understanding how decorators work |
| Decorator with Arguments | Functions that accept parameters |
| Before and After Execution | Logging and monitoring |
| User Input | Interactive programs |
A decorator adds extra functionality to a function without changing its original code.
Decorators are created using functions that return another function.
The @decorator syntax is used to apply a decorator.
Decorators can work with functions that have parameters.
They are commonly used for logging, authentication, timing, caching, and validation.
Stay tuned for Day 101 of the #150DaysOfPython series! ๐
Python Developer August 28, 2026 Python Coding Challenge No comments
Python Coding August 28, 2026 Books, Python No comments
If you are a Python developer looking to move beyond writing simple scripts and start building practical, scalable automation workflows, Python Automation Cookbook – Third Edition by Jaime Buelta is a book worth exploring.
This third edition expands the cookbook approach with updated recipes and new material focused on AI, MCP, and intelligent automation.
Python Automation Cookbook takes a practical, recipe-based approach to automation. Instead of focusing only on theory, the book shows how Python can be used to solve real-world automation problems through reusable techniques and examples.
The book progresses from fundamental Python automation concepts toward more advanced topics involving web scraping, APIs, system operations, testing, AI models, MCP, and AI agents.
Some of the major areas covered include:
One of the most interesting aspects of this edition is its focus on AI-powered automation.
Traditional automation generally follows predefined rules:
Input → Python Script → Rules → Output
AI-powered automation can introduce another layer:
Input → Python → AI Model → Decision → Action
This allows developers to build workflows that can interpret information, make decisions, interact with external systems, and automate more complex tasks.
The inclusion of AI models, MCP, and intelligent agents makes this edition particularly relevant for developers interested in the future of automation.
The cookbook-style structure is one of the book's biggest strengths.
You don't necessarily have to read the entire book from beginning to end. Instead, you can use individual recipes as a reference when you encounter a particular automation problem.
This makes the book especially useful for developers who prefer learning by building and experimenting with practical examples.
This book is particularly useful for:
It is better suited to readers who already have a basic understanding of Python rather than complete beginners.
Overall Rating: 4.5/5
The biggest strength of Python Automation Cookbook – Third Edition is its practical approach.
Python is one of the most popular languages for automation, but knowing Python syntax is only the beginning. The real value comes from learning how to connect Python with files, operating systems, APIs, websites, external services, and now AI systems.
This book provides a useful bridge between Python programming and real-world automation.
The addition of AI-focused content is another major advantage. Developers can learn how traditional automation techniques can be combined with modern AI capabilities to create smarter workflows.
The book is also substantial enough to work as a long-term reference, rather than something you simply read once.
This isn't a book I'd recommend as your first-ever Python resource. Beginners should learn Python fundamentals before diving into many of the recipes.
Also, AI, MCP, and agent technologies are evolving rapidly. Some AI-specific approaches may change over time, while the fundamental Python automation techniques are likely to remain useful much longer.
Python Automation Cookbook – Third Edition is a strong choice for developers who want to turn their Python skills into useful automation systems.
What makes this edition especially interesting is the combination of Python automation + AI + MCP + intelligent agents.
If you want to learn how Python can automate repetitive tasks, connect different systems, work with APIs, scrape information, and interact with modern AI technologies, this book is a valuable addition to your technical library.
Recommended for: Python developers, automation enthusiasts, DevOps professionals, and developers interested in AI-powered workflows.
Rating: ⭐ 4.5/5
Probability distributions are often compared using statistical divergences. These measures tell us how different two probability distributions are. One of the best-known examples is the Kullback–Leibler (KL) divergence, which is widely used in statistics, information theory, and Machine Learning.
The paper “Statistical Divergences between Densities of Truncated Exponential Families with Nested Supports: Duo Bregman and Duo Jensen Divergences” by Frank Nielsen explores what happens when the probability distributions being compared belong to truncated exponential families with nested supports. The work introduces new forms of divergence called duo Fenchel–Young, duo Bregman, and duo Jensen divergences.
An exponential family is a broad class of probability distributions that can be represented using a common mathematical structure.
It includes important distributions such as:
The paper describes exponential families using parameters, sufficient statistics, and a log-normalizer (cumulant function).
A truncated distribution is created by restricting the possible values of a random variable to a particular region.
For example, a normal distribution normally has support:
(-∞, +∞)
If we only keep values greater than zero:
[0, +∞)
we obtain a truncated version of the distribution.
The paper uses the half-normal distribution as an example of a truncated exponential family whose support is contained within the support of the original normal family.
The idea of nested support is central to the paper.
Suppose:
Support A ⊂ Support B
Then every possible value in A is also contained in B.
For example:
[0, +∞) ⊂ (-∞, +∞)
This relationship allows the paper to study divergences between distributions defined over related but different regions.
The KL divergence measures how one probability distribution differs from another.
It can be represented conceptually as:
Distribution P
↓
Compare With Q
↓
KL Divergence
A fundamental property is:
KL(P || Q) ≥ 0
and it becomes zero when the distributions are identical under the usual conditions. The paper uses KL divergence as the starting point for developing its generalized divergence formulas.
For distributions belonging to the same exponential family, KL divergence has an important connection with Bregman divergence.
A Bregman divergence is generated by a convex function and measures a generalized notion of difference between two parameter points.
Conceptually:
Probability Distributions
↓
Exponential Family
↓
Convex Function
↓
Bregman Divergence
This connection is one of the foundations of information geometry.
The interesting contribution of the paper is that when distributions come from different exponential families, particularly truncated families with nested supports, the ordinary Bregman formulation is no longer sufficient.
The paper introduces a duo Fenchel–Young divergence, which can equivalently be expressed as a duo Bregman divergence. Under a majorization condition on the convex generators, the resulting divergence is guaranteed to be non-negative.
The idea can be summarized as:
Two Statistical Families
↓
Two Convex Generators
↓
Duo Divergence
↓
Measure of Difference
The paper also studies skewed Bhattacharyya distances between truncated exponential families.
It shows that these distances can be represented using corresponding skewed duo Jensen divergences.
This creates another connection between:
Probability → Convexity → Divergences → Information Geometry
One practical mathematical example in the paper is the KL divergence between truncated normal distributions.
Normal distributions are extremely important in statistics and Machine Learning, so understanding how their divergence behaves after truncation is useful for probabilistic modeling.
The paper derives a formula expressing this KL divergence using the proposed duo divergence framework.
Comparing probability distributions is important in many areas of AI and Data Science.
For example:
If two datasets or models produce different probability distributions, a suitable divergence can provide a quantitative measure of that difference.
The paper sits at the intersection of several mathematical fields:
Probability Theory
↓
Statistics
↓
Convex Analysis
↓
Information Geometry
↓
Machine Learning
Information geometry treats probability distributions as geometric objects. Divergences such as Bregman and Jensen-type divergences can then be interpreted as ways of measuring relationships between these objects.
Convex functions are central to the paper.
Convexity provides useful mathematical properties for defining divergences and optimization objectives.
For example, a convex function has the general shape:
Curve bends upward
and this structure allows us to construct meaningful measures of difference between parameter values.
The paper uses relationships between convex generators to establish non-negativity of its duo divergences.
Imagine two distributions:
P = Normal distribution restricted to [0, 5]
Q = Normal distribution restricted to [0, 10]
Their supports are nested:
[0, 5] ⊂ [0, 10]
We want to measure:
How different is P from Q?
The paper's framework provides a mathematical way to express such divergences using the corresponding exponential-family structures and convex generators.
The paper's key contributions can be summarized as:
A generalized divergence for pairs of exponential-family structures.
An equivalent Bregman-style representation.
A framework for calculating KL divergence between truncated exponential-family distributions with nested supports.
A concrete formula for KL divergence between truncated normal distributions.
A connection between skewed Bhattacharyya distances and skewed duo Jensen divergences.
This paper is most suitable for readers interested in:
A background in probability, linear algebra, calculus, convexity, and exponential families will make the mathematics considerably easier to follow.
Statistical Divergences between Densities of Truncated Exponential Families with Nested Supports is a mathematically advanced paper that extends familiar ideas such as KL divergence and Bregman divergence to a more complicated setting involving truncated exponential families with nested supports.
Its central progression can be summarized as:
Exponential Families
↓
Truncated Distributions
↓
KL Divergence
↓
Duo Fenchel–Young Divergence
↓
Duo Bregman Divergence
↓
Duo Jensen Divergence
The paper is particularly valuable for understanding how convex geometry and probability theory can work together to create new ways of comparing statistical distributions.
Python Developer August 27, 2026 Python Coding Challenge No comments
Python Developer August 27, 2026 Python Coding Challenge No comments
Free Books Python Programming for Beginnershttps://t.co/uzyTwE2B9O
— Python Coding (@clcoding) September 11, 2023
Top 10 Python Data Science book
— Python Coding (@clcoding) July 9, 2023
๐งต:
Top 4 free Mathematics course for Data Science ! pic.twitter.com/s5qYPLm2lY
— Python Coding (@clcoding) April 26, 2024
Web Development using Python
— Python Coding (@clcoding) December 2, 2023
๐งต: