What is the best practice?
1) have a function be able to take in None?
2) practice to not to send None to a func
is it just personal preference or are there any pros/cons to this?
I have a func
def parse_path(path):
site = None
site_pattern = re.compile('(fl|ny|wa|tx)')
match = site_pattern.search(path)
if match:
site = match.group(0)
return site
so obviously if i pass in None to parse_path, it will complain.
TypeError: expected string or buffer
so should I always be conscious of what to put in to a func or should a func be flexible so it deals with None?
Noneis not special here. What if I passed in a list, or a float instead?Noneis not a supported type, then you should fix the code calling your function to not pass inNone.