python - How to let compiler interpret as bolean context -


i wrote following function:

def has_voted(request, question):     cookie = request.cookies.get(cookie_name)     ip = get_client_ip(request)     return ((cookie , re.match(cookie_pattern, cookie) ,             question.id in map(int, cookie.split('-'))) or             (ip , is_valid_ip_address(ip) ,             question.voter_set.filter(ip=ip).exists())) 

the function returns none, want compiler interpret in boolean context if-statements:

if cookie:     pass 

if want return boolean, return boolean:

return bool((cookie , re.match(cookie_pattern, cookie) ,             question.id in map(int, cookie.split('-'))) or             (ip , is_valid_ip_address(ip) ,             question.voter_set.filter(ip=ip).exists())) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -