Blog Category: python

How to globally customize exception stack traces in Python


The Python language has some useful flexibility when it comes to exceptions. Programmers want as much relevant information as we can get when our code does something unexpected. Python's default behavior for an unhandled exception is to print a stack trace, the error type, and the error description. This is sent to sys.stderr (typically, the console), like this: ...

How to make iterators out of Python functions without using yield


The built-in iter() method in Python 2.2 and later hides a neat trick which is not well-known. Typically iter() is used to return an iterator from an iterable object: ...