I have the following class
class A(object):
def __unicode__(self):
return u'A'
def __str__(self):
return 'AA'
>>> u"{}".format(A())
u'A'
>>> "{}".format(A())
'AA'
>>> str(A())
'AA'
According to the documentation ,
"Harold smart {0! S}" # Calls str () on the first argument
Why does this still return u'A 'not u'AA' ??
>>> u"{0!s}".format(A())
u'A'
I would expect it to be the same as
>>> u"{}".format(str(A()))
u'AA'
source
share