This doesn't have to be limited to Python 3, althought Py3 does make it more convenient.

Check this out:
http://stackoverflow.com/a/9324811/194311