3 ms·
I use stackprinter[1] for the same. It's advisable to suppress printing of library functions (`suppressed_paths=["lib/python"])`) otherwise deep stack traces (a
by andreareina 6y ago
I use stackprinter[1] for the same. It's advisable to suppress printing of library functions (`suppressed_paths=["lib/python"])`) otherwise deep stack traces (as some libraries---hello pandas---like to produce) will cause the actually-problematic code to be elided. Long reprs are also truncated so your 2GB JSON buffer isn't going to blow up your trace.
this:
Traceback (most recent call last):
File "demo.py", line 12, in <module>
dangerous_function(somelist + anotherlist)
File "demo.py", line 6, in dangerous_function
return sorted(blub, key=lambda xs: sum(xs))
File "demo.py", line 6, in <lambda>
return sorted(blub, key=lambda xs: sum(xs))
TypeError: unsupported operand type(s) for +: 'int' and 'str'
becomes:
File demo.py, line 12, in <module>
9 somelist = [[1,2], [3,4]]
10 anotherlist = [['5', 6]]
11 spam = numpy.zeros((3,3))
--> 12 dangerous_function(somelist + anotherlist)
13 except:
..................................................
somelist = [[1, 2, ], [3, 4, ], ]
anotherlist = [['5', 6, ], ]
spam = 3x3 array([[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]])
..................................................
[...]
File demo.py, line 6, in <lambda>
3
4
5 def dangerous_function(blub):
--> 6 return sorted(blub, key=lambda xs: sum(xs))
7
..................................................
xs = ['5', 6, ]
..................................................
TypeError: unsupported operand type(s) for +: 'int' and 'str'
[1] https://github.com/cknd/stackprinter https://github.com/cknd/stackprinter