Articles on Trending Technologies

Technical articles with clear explanations and examples

Explain Inheritance vs Instantiation for Python classes.

Akshitha Mote
Akshitha Mote
Updated on 24-Mar-2026 11K+ Views

In Python, inheritance and instantiation are two fundamental object-oriented programming concepts. Inheritance allows one class to derive properties from another class, while instantiation creates objects from a class definition. Understanding Inheritance Inheritance is the capability of one class to derive or inherit properties from another class. The class that derives properties is called the derived class or child class, and the class from which properties are being derived is called the base class or parent class. Syntax class Parent: # base class pass class Child(Parent): # derived class ...

Read More

Python Library API for Docker

Raunak Jain
Raunak Jain
Updated on 24-Mar-2026 870 Views

You can access, manage and manipulate docker objects such as containers, images, clusters, swarms, etc. using a Python library API. You can do pretty much anything that docker commands let you do. This comes very handy when you are using a python app such as Django or Flask and you want to maintain your docker container using the same python script that you use for the application. Installation To use the python library API for docker, you need to install a package called docker-py. You can do so using the following pip command. If you have python 2 installed, replace ...

Read More

How do I enumerate functions of a Python class?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 274 Views

Python provides several ways to enumerate (list) the functions and methods of a class. The most common approach uses the inspect module to examine class members and filter for callable methods. Using inspect.getmembers() The inspect.getmembers() function returns all members of a class. Use inspect.isfunction or inspect.ismethod as a predicate to filter only functions ? import inspect class SampleClass: def __init__(self): self.x = 10 def method_one(self): return ...

Read More

How to convert a string to a Python class object?

Akshitha Mote
Akshitha Mote
Updated on 24-Mar-2026 14K+ Views

Converting a string to a Python class means accessing a Python class using its name stored as a string, allowing dynamic creation of objects at runtime. This is useful for factory patterns, plugin systems, and configuration-driven object creation. Using globals() Function The globals() function retrieves classes from the global namespace using their string names ? class Bike: def start(self): print("Bike started!") class_name = "Bike" cls = globals()[class_name] # Convert string to class obj = cls() obj.start() print(type(obj)) The output of ...

Read More

How I can create Python class from JSON object?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 1K+ Views

Creating Python classes from JSON objects can be accomplished using the python-jsonschema-objects library, which is built on top of jsonschema. This library provides automatic class-based binding to JSON schemas for use in Python. Installing the Required Library First, install the python-jsonschema-objects library ? pip install python-jsonschema-objects Defining a JSON Schema Let's start with a sample JSON schema that defines the structure of a Person object ? schema = '''{ "title": "Example Schema", "type": "object", "properties": { ...

Read More

When are python classes and class attributes garbage collected?

Akshitha Mote
Akshitha Mote
Updated on 24-Mar-2026 551 Views

In Python, a class is a blueprint for creating objects. It contains attributes and methods that define the behavior of objects created from it. Understanding when classes and their attributes are garbage collected is crucial for memory management. class TutorialsPoint: def __init__(self): print("Welcome to TutorialsPoint.") obj1 = TutorialsPoint() Welcome to TutorialsPoint. When are Python Classes Garbage Collected? In Python, classes are garbage collected when there are no references to the class itself and no instances ...

Read More

Would you recommend to define multiple Python classes in a single file?

Akshitha Mote
Akshitha Mote
Updated on 24-Mar-2026 5K+ Views

Yes, it is recommended to define multiple Python classes in a single file when they are logically related. This approach improves code organization and readability while avoiding the overhead of managing numerous small files. If we define one class per file, we may end up creating a large number of small files, which can be difficult to keep track of. Placing all the interrelated classes in a single file increases the readability of the code. If multiple classes are not interrelated, we can place them in different files to improve maintainability and scalability. What is a Python ...

Read More

Is there any tool that can convert an XSD file to a Python class as JAXB does for Java?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 1K+ Views

When working with XML Schema Definition (XSD) files in Python, you often need to generate Python classes similar to how JAXB works for Java. generateDS is the most popular tool for converting XSD files to Python classes with full XML binding capabilities. What is generateDS? generateDS is a Python tool that automatically generates Python classes from XSD schema files. It creates complete data binding classes with methods for XML serialization, deserialization, and data access ? Installation Install generateDS using pip ? pip install generateDS Basic Usage Convert an XSD file to ...

Read More

How to get the class name of an instance in Python?

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 6K+ Views

In Python object-oriented programming, getting the class name of an instance is a common requirement. Python provides several approaches to retrieve the class name from any object or instance. Using __class__.__name__ The most straightforward method uses the __class__ attribute combined with __name__ to get the class name ? class Animal: def __init__(self, name): self.name = name lion = Animal("Lion") print(lion.__class__.__name__) Animal The __class__ attribute returns the class object, while __name__ gives the actual class name as a string. ...

Read More

Explain Python class method chaining

Sarika Singh
Sarika Singh
Updated on 24-Mar-2026 16K+ Views

In object-oriented programming, method chaining is a programming technique where multiple method calls are linked together in a single expression. Each method returns an object (typically self), allowing the next method to be called on the result. Method chaining provides two key benefits ? Reduced code length − No need to create intermediate variables for each step Improved readability − Operations flow sequentially in a clear, logical order How Method Chaining Works For method chaining to work, each method must return an object (usually self) so the next method can be called on it. ...

Read More
Showing 7441–7450 of 61,303 articles
« Prev 1 743 744 745 746 747 6131 Next »
Advertisements