Yes, it may crash for custom classes:
>>> class C(object): ... def __str__(self): ... return 'oops: ' + oops ... >>> c = C() >>> str(c) NameError: global name 'oops' is not defined
It may even crash for some built-in classes such as unicode :
>>> u = u'\xff' >>> s = str(u) UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in position 0: ordinal not in range(128)
source share