# -*- 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 codelines = [ "int('foo')", "max()", "foo", "5/0", "max.foo", "__import__('foobar')", "[][5]", "int(1e1000)", # these are different on py>=2.6 "{}['foo']", "2+*3", "u'\u1234'.encode('ascii')", "'\xc3'.decode('ascii')", ] for codeline in codelines: print_exception(codeline)