Answer the question
In order to leave comments, you need to log in
How to add a new variable with a custom name to an object?
Not needed yet, but very interesting... Let's say I want to add to
class Test:
def __init__(self):
self.sma=None
t=Test()
for i in range(0,3):
exec('t.sma_'+str(i)+'=None')
print(t.sma_0) // None
print(t.sma_1) // None
print(t.sma_2) // None
print(t.sma_3) // None
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question