I'm tring to create class instances in a loop. All instances need to be assinged to a different variable. These variables can be a sequence of letters like [a,b,c].
class MyClass(object):
pass
for i in something:
#create an instance
If the loop turns 3 times, I want the loop make something like that:
a = MyClass()
b = MyClass()
c = MyClass()
Is there a way to do that?
Using independent variable names this way is a bit odd; using either a dict or a list, as shown above, seems better.
Splitting it down the middle, how about
a,b,c = (MyClass() for _ in range(3))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With