# -*- coding: utf-8 -*- """ Run this script on py2.5 and py2.6 to see the differences. """ def print_exception(code): """ Evaluate the code and print the repr, str and unicode of the error. """ try: eval(code) except Exception, error: print '* %s raised by "%s"' % (error.__class__.__name__, code) print ' repr :', repr(error) print ' str :', str(error) print ' unicode:', unicode(error) print same_message = [ "int('foo')", "max()", "foo", "5/0", "max.foo", "__import__('foobar')", "[][5]", "int(1e1000)" ] # these are different on py>=2.6 different_message = [ "open('flooble')", "{}['foo']", "2+*3", "u'\u1234'.encode('ascii')", "'\xc3'.decode('ascii')", ] print '*** The str() and unicode() of these exceptions is the same ***\n' for codeline in same_message: print_exception(codeline) print '*** The str() and unicode() of these exceptions is the different ***\n' for codeline in different_message: print_exception(codeline)