[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: Call function via literal name
From: TUA <kai.peters () gmail ! com>
Date: 2016-07-29 23:41:18
Message-ID: ffd7bb37-4b21-470e-806f-0024f456fb69 () googlegroups ! com
[Download RAW message or body]
On Friday, 29 July 2016 13:35:30 UTC-7, TUA wrote:
> Rather than do this:
>
> if test['method'] == 'GET':
> res = requests.get(test['endpoint'], auth=test['auth'], verify=False)
> elif test['method'] == 'POST':
> res = requests.post(test['endpoint'], auth=test['auth'], verify=False, \
> json=test['body']) elif test['method'] == 'PUT':
> res = requests.put(test['endpoint'], auth=test['auth'], verify=False, \
> json=test['body']) elif test['method'] == 'DELETE':
> res = requests.delete(test['endpoint'], auth=test['auth'], verify=False)
> elif test['method'] == 'HEAD':
> res = requests.head(test['endpoint'], auth=test['auth'], verify=False)
>
> I would like to call the requests method that corresponds to test['method'] by \
> finding that function by name - how can I achieve that?
thanks gentlemen - that hit the spot!
--
https://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic