0

Is it possible to do something like this in Python?

class MyClass():
    def __init__(self):
        someValue = 42

        str = 'a'
        # self.a = someValue
        str = 'xyz'
        # self.xyz = someValue       

Essentially what I want to achieve is by reading the value of str (say the value of str resolves to 'myValue'), the code adds an additional attribute (self.myValue) into the class.

John Tan
  • 1,331
  • 1
  • 19
  • 35

0 Answers0