Firstly, is there one?
If not, is there a nice way to force something like
print '%s' % obj
to call obj.__unicode__
instead of obj.__str__
?
Just use a unicode format string, rather than having a byte string in that role:
>>> class X(object):
... def __str__(self): return 'str'
... def __unicode__(self): return u'unicode'
...
>>> x = X()
>>> print u'%s' % x
unicode
No. It wouldn't make sense for this to be the case.
print (u"%s" % obj).encode(some_encoding)
will use obj.__unicode__
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With