Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python class reflect method of member instance

url = input("input url:")  # Enter www.xxx.com/accout/fun to return the result of fun and 404 if it does not exist.
target_module, target_func = url.split('/')
# module = __import__('backend.'+target_module) #Using fromlist=True, you can import backend
module = __import__('backend.'+target_module, fromlist=True) #Using fromlist=True, you can import backend.accout.
func_name = url.split('/')[-1]
if hasattr(module, target_func): #Determine whether module contains target_func members
    target_func = getattr(module, target_func) #Get a reference to func_name
    target_func() #Execution function
Source by programmer.ink #
 
PREVIOUS NEXT
Tagged: #python #class #reflect #method #member #instance
ADD COMMENT
Topic
Name
6+5 =