Posts

Showing posts from August, 2013

Invalid positonal args cannot be passed over as kwargs using **kwargs

Input: def a(x, y=None):    print x, y def b(x, **kw):     a(x, **kw) def c(x, y):     print x, y c(1, y=1) b(1, y=2) b(1, 3) Output: 1 1 1 2 Traceback (most recent call last):   File "a.py", line 12, in <module>     b(1, 3) TypeError: b() takes exactly 1 argument (2 given)

Try/Except vs Exception handling

try:   foo() except:   pass or try:   foo() except Exception:   pass Difference is that the first will catch everything including OsError, KeboardInterrupt, SystemExit which are derived from BaseException instead of Exception class. More documentation for details: try statement — http://docs.python.org/reference/compound_stmts.html#try exceptions — http://docs.python.org/library/exceptions