Wrapper Class in Python Last Updated : 21 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Decoration is a way to specify management code for functions and classes. Decorators themselves take the form of callable objects that process other callable objects. A Class Decorator is similar to function decorators, but they are run at the end of a class statement to rebind a class name to a callable (e.g functions). As such, they can be used to either manage classes just after they are created or insert a layer of wrapper logic to manage instances when they are later created. Class decorator can be used to manage class object directly, instead of instance calls - to increase/modify a class with new methods. Class decorators are strongly related to function decorators, in fact, they use nearly the same syntax and very similar coding pattern but somewhere logic differs. Note: For more information, refer to Decorators in Python Syntax: Syntactically, class decorators appear just before class statements. @decorator class Class_Name: ... inst = Class_Name(50) This piece of code is equivalent to class Class_Name: ... Class_Name = decorator(Class_Name) inst = Class_Name(50); Let's understand the syntax, and how its works with an example: Example: Python3 1== # decorator accepts a class as # a parameter def decorator(cls): class Wrapper: def __init__(self, x): self.wrap = cls(x) def get_name(self): # fetches the name attribute return self.wrap.name return Wrapper @decorator class C: def __init__(self, y): self.name = y # its equivalent to saying # C = decorator(C) x = C("Geeks") print(x.get_name()) OUTPUT: Geeks In this example, the decorator rebinds the class C to another class Wrapper, which retains the original class in an enclosing scope and creates and embeds an instance (wrap) of the original class when it's called. In more easy language, @decorator is equivalent to C = decorator(C) which is executed at the end of the definition of class C. In the decorator body, wrapper class modifies the class C maintaining the originality or without changing C. cls(x) return an object of class C (with its name attribute initialized with the value of x). The method get_name return the name attribute for the wrap object. And finally in the output "Geeks" gets printed. So, this was an overview of the decorator or wrapper for the class. The class decorators are used to add additional functionality to the class without changing the original class to use as required in any situation. Comment More infoAdvertise with us Next Article Wrapper Class in Python S shubhamkumarlhh Follow Improve Article Tags : Python Python Decorators Practice Tags : python Similar Reads self in Python class In Python, self is a fundamental concept when working with object-oriented programming (OOP). It represents the instance of the class being used. Whenever we create an object from a class, self refers to the current object instance. It is essential for accessing attributes and methods within the cla 6 min read Function Wrappers in Python Function wrappers, also known as decorators, are a powerful and useful feature in Python that allows programmers to modify the behavior of a function or class without changing its actual code. Decorators enable wrapping another function to extend or alter its behavior dynamically at runtime.Example: 2 min read Inner Class in Python Python is an Object-Oriented Programming Language, everything in Python is related to objects, methods, and properties. A class is a user-defined blueprint or a prototype, which we can use to create the objects of a class. The class is defined by using the class keyword.Example of classPython# creat 5 min read classmethod() in Python The classmethod() is an inbuilt function in Python, which returns a class method for a given function. This means that classmethod() is a built-in Python function that transforms a regular method into a class method. When a method is defined using the @classmethod decorator (which internally calls c 8 min read Python Functools - update_wrapper() The functools module in Python deals with higher order functions, that is, functions operating on(taking as arguments) or returning functions and other such callable objects. The functools module provides a wide array of methods such as cached_property(func), cmp_to_key(func), lru_cache(func), wraps 6 min read Class or Static Variables in Python All objects share class or static variables. An instance or non-static variables are different for different objects (every object has a copy). For example, let a Computer Science Student be represented by a class CSStudent. The class may have a static variable whose value is "cse" for all objects. 9 min read Using a Class with Input in Python In this article, we will see how to take input using class in Python. Using a Class with Input in Python It is to be noted that while using class in Python, the __init__() method is mandatory to be called for declaring the class data members, without which we cannot declare the instance variable (da 2 min read python class keyword In Python, class keyword is used to create a class, which acts as a blueprint for creating objects. A class contains attributes and methods that define the characteristics of the objects created from it. This allows us to model real-world entities as objects with their own properties and behaviors.S 1 min read Python issubclass() We know that inheritance is one of the building blocks of the Object-Oriented Programming concept. One class can derive or inherit the properties from some other class. It also provides the reusability of code. We donât have to write the same code again and again. Also, it allows us to add more feat 3 min read Decorators in Python In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are 10 min read Like