Creating multiple instances of a class dynamically
In this section, let’s look at creating more than one instance of a class dynamically. For this example, we will be making use of a built-in Python function named globals
to create dynamic object names, along with the type
function that we use to create dynamic objects. Refer to the following steps:
- Let’s create a new class named
Product
without any attributes or methods. Instead of defining the attributes within the class and creating an instance of the class, let’s create multiple instances with their own attributes:class Product(): '''attributes...''' '''methods...''' pass
- Next, we will be creating three dictionary items in a list named
details
:details = [{'branchID' : 202, 'ProductID...