Skip to content Skip to sidebar Skip to footer

Calling Function Names With Strings Python

I would like to be able to pass a call of either get, post, delete, etc, into my requests function. So instead of having all these different functions for each RESTFULness, I'd lik

Solution 1:

I think you probably want getattr:

def call(method):
    f = getattr(requests, method)
    return f('https://api....', ...);

Post a Comment for "Calling Function Names With Strings Python"