python
[Python] Create a list of objects using class names
# In Python, the name of the class refers to the class instance. Consider:
class A: pass
class B: pass
class C: pass
lst = [A, B, C]
# instantiate second class
b_instance = lst[1]()
print(b_instance)
Was this helpful?
Similar Posts
- Change column orders using column names list - Pandas Dataframe
- Get column names from Pandas DataFrame as a python List
- Reorder dataframe columns using column names in pandas
- Add suffix/prefix to column names of Pandas DataFrame
- Create a flat list from list of lists in Python
- [Python] Namedtuples can be a great alternative to defining a class manually
- Retrieving all objects in Django