This question is asked every day in some variation. The answer is: keep your data out of your variable names, and this is the obligatory blog post.
In this case, why not make a list of objs?
objs = [MyClass() for i in range(10)]
for obj in objs:
other_object.add(obj)
objs[0].do_sth()
More Related Contents:
- How to make an object indestructible even with force deletion?
- How to print instances of a class using print()?
- How do I call a parent class’s method from a child class in Python?
- Saving and loading multiple objects in pickle file?
- Getting an instance name inside class __init__() [duplicate]
- What is the difference between __init__ and __call__?
- Difference between ‘cls’ and ‘self’ in Python classes?
- How do I correctly setup and teardown for my pytest class with tests?
- Getting container/parent object from within python
- How can I create an object and add attributes to it?
- “Enabling” comparison for classes [duplicate]
- Why is the id of a Python class not unique when called quickly?
- What is the difference between class and instance variables?
- super() fails with error: TypeError “argument 1 must be type, not classobj” when parent does not inherit from object
- Python dictionary from an object’s fields
- Attaching a decorator to all functions within a class
- class variables is shared across all instances in python? [duplicate]
- python assign values to list elements in loop
- assigning class variable as default value to class method argument
- Python Class Members Initialization
- What does object’s __init__() method do in python? [duplicate]
- Class (Static) variables and methods in Python
- How to make a copy of a 2D array in Python? [duplicate]
- Passing variables, creating instances, self, The mechanics and usage of classes: need explanation [closed]
- How do you change the value of one attribute by changing the value of another? (dependent attributes)
- How to extend a class in python?
- Python calling method in class
- How to declare a static attribute in Python?
- How to find instance of a bound method in Python?
- How can two Python objects have same id but ‘is’ operator returns False?