Sometimes I need to create new variables with a suffix using a variable, which I can with something like:
Number=5
locals()['First'+str(Number)]=5
Resulting in the variable First5 which is = 5.
How can I do the same thing in a class instance?
class foo:
def appender(self,bar):
for i in range(bar):
self.locals()['Number'+str(i)]=i
#-----
qq=foo()
qq.appender(3) #issues...
I would like this to create qq.Number0, qq.Number1 and qq.Number2, but it tells me that foo has no instance of locals. How can I concatenate strings to create new variables in my instance? Thanks!