All Questions

1882
votes
30answers
102935 views

"Least Astonishment" and the Mutable Default Argument

Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue: def foo(a=[]): a.append(5) return a Python novices would expect this function to always ...
8
votes
5answers
5183 views

"Boolean" operations in Python (ie: the and/or operators)

This method searches for the first group of word characters (ie: [a-zA-Z0-9_]), returning the first matched group or None in case of failure. def test(str): m = re.search(r'(\w+)', str) if m:...

Previous Next