Tuesday, January 16, 2018

Python : Call function using string (similar to Java Reflection API )

Python : Call function using string (similar to Java Reflection API )


# Calling
class animals:
    def dog(self):
        print("bark")
       
    def lion(self):
        print("roar")


obj=getattr(animals(),'dog')
obj()

result :
bark

1 comment:

  1. A great content and very much useful to the visitors. Looking for more updates in future.

    PYTHON Training in Chennai

    ReplyDelete