They are identical, and this is only a matter of preference. In terms of Zen Python, etc. There really is no “better” way, since both explicitly express that they get a unicode representation child.tag. Mechanically they do the same:
>>> class foo(object):
def __init__(self, val):
self.val = val
def __str__(self):
return "str: %s" % self.val
def __unicode__(self):
return "unicode: %s" % self.val
>>> f = foo("bar")
>>> u'%s' % f
u'unicode: bar'
>>> unicode(f)
u'unicode: bar'
>>> '%s' % f
'str: bar'
source
share