Storing a list of object instances is very simple
class MyClass(object):
def __init__(self, number):
self.number = number
my_objects = []
for i in range(100):
my_objects.append(MyClass(i))
# later
for obj in my_objects:
print obj.number
More Related Contents:
- python assign values to list elements in loop
- Why doesn’t assigning to the loop variable modify the original list? How can I assign back to the list in a loop? [duplicate]
- I don’t know how to display step 3 for this assignment
- How do I concatenate items in a list to a single string?
- Split a string by a delimiter in python
- Access a particular field in arbitrarily nested JSON data [duplicate]
- Is there a zip-like function that pads to longest length?
- Why does this iterative list-growing code give IndexError: list assignment index out of range?
- Different behaviour for list.__iadd__ and list.__add__
- Slicing a list in Python without generating a copy
- Non-alphanumeric list order from os.listdir()
- How do I check if there are duplicates in a flat list?
- Memory errors and list limits?
- [] and {} vs list() and dict(), which is better?
- How to find the maximum value in a list of tuples? [duplicate]
- How to access List elements
- In Python, why is list[] automatically global?
- Python: Removing spaces from list objects [duplicate]
- Understand Python swapping: why is a, b = b, a not always equivalent to b, a = a, b?
- Why do I get “List index out of range” when trying to add consecutive numbers in a list using “for i in list”? [duplicate]
- How do I sort this list in Python, if my date is in a String?
- How can I format a list to print each element on a separate line in python? [duplicate]
- Group list by values [duplicate]
- What are dict_keys, dict_items and dict_values?
- Ordered intersection of two lists in Python
- What to consider before subclassing list?
- How do I send list of dictionary as Body parameter in FastAPI?
- Python Sort One List According to Another List
- What is the cost/ complexity of insert in list at some location?
- Check list monotonicity