2014-03-26 15:35:13 -06:00
|
|
|
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))
|
2014-04-05 04:33:04 -06:00
|
|
|
print(getattr(a, "_none_such", 123))
|
|
|
|
print(getattr(list, "foo", 456))
|
2014-06-07 16:13:35 -06:00
|
|
|
print(getattr(a, "va" + "r2"))
|