2

The following code:

class A:
    def __init__(self, a,b):
        self.a=a
        self.b=b
temp_text=A(1,2)

If i want to get temp_text.a. How could i get this from a string "a"? such as :temp_text."a"

wkl
  • 77,184
  • 16
  • 165
  • 176
Haoyu Shi
  • 31
  • 3

1 Answers1

2

You need the function getattr for this:

getattr(temp_text, 'a')
DainDwarf
  • 1,651
  • 10
  • 19