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
Post a Comment