getattr1.py 208 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class A:

    var = 132

    def __init__(self):
        self.var2 = 34

    def meth(self, i):
        return 42 + i


a = A()
print(getattr(a, "var"))
print(getattr(a, "var2"))
print(getattr(a, "meth")(5))