If suppose i have a class name as a string, how can i use reflection to invoke its static member known before-hand? Some like this:
someInspectionMechanism("FooClass").staticMethod()
If suppose i have a class name as a string, how can i use reflection to invoke its static member known before-hand? Some like this:
someInspectionMechanism("FooClass").staticMethod()
Use locals()
or globals()
to get the namespace dictionary, and look for a class with the name you want. The fact that you're using a static method is not relevant.
Example:
class Test:
@staticmethod
def method():
return 'called static method'
assert locals()['Test'].method() == 'called static method'