Created
May 2, 2012 09:13
-
-
Save dhendo/2575427 to your computer and use it in GitHub Desktop.
Some tests on the semantics of python string handling...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
def main(): | |
try: | |
raise Exception(u"Something went wrong ³£$%^") | |
except Exception as e2: | |
pass | |
items = (1, 33.2, None, u'³£$%^', u'𐎴', {'dict': True, 'subdict': {'items': 'yes'}}, (('Tuple', True),),['item1', {'secondItem': False}], Exception, e2) | |
for item in items: | |
print "\n----------------------\n" | |
try: | |
print item | |
except Exception as e: | |
print u"x Failed to print value" | |
print "-- Unicode --" | |
try: | |
print u" [Concatenate] " + item | |
except Exception as e: | |
print u"x [Concatenate] Exception: %s" % e | |
try: | |
print u" [Format] %s" % item | |
except Exception as e: | |
print u"x [Format] Exception: %s" % e | |
try: | |
print u" [str()] " + str(item) | |
except Exception as e: | |
print u"x [str()] Exception: %s" % e | |
try: | |
print u" [unicode()] " + unicode(item) | |
except Exception as e: | |
print u"x [unicode()] Exception: %s" % e | |
print "-- ASCII --" | |
try: | |
print " [Concatenate] " + item | |
except Exception as e: | |
print "x [Concatenate] Exception: %s" % e | |
try: | |
print " [Format] %s" % item | |
except Exception as e: | |
print "x [Format] Exception: %s" % e | |
try: | |
print " [str()] " + str(item) | |
except Exception as e: | |
print "x [str()] Exception: %s" % e | |
try: | |
print " [unicode()] " + unicode(item) | |
except Exception as e: | |
print "x [unicode()] Exception: %s" % e | |
#print "\n----------------------\n" | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment