Get Object References in Python with getattr
Get Object References
Get Object References with getattr
li = ["A", "B"]
# w w w . j av a2s . c om
print li.pop
print getattr(li, "pop")
print getattr(li, "append")
print li
print getattr({}, "clear")
print getattr((), "pop")
The code above generates the following result.
getattr with module
import math# from ww w. j a v a2s . c o m
print math.abs
print getattr(math, "abs")
object = math
method = "abs"
print getattr(object, method)
print type(getattr(object, method))
The code above generates the following result.