良好做法__unicode __(个体经营)

cle*_*ula 0 python string unicode

解决这个简单问题的好习惯是什么?

def __unicode__(self):
    return unicode(self.typePlace + " " + self.name)
Run Code Online (Sandbox Code Playgroud)

TypeError:+的不支持的操作数类型:'TipoLugar'和'str'

And*_*ter 7

据推测,typePlace它本身就是一个具有自己__str__()和/或__unicode__()函数的对象(如果它不是,并且它是一个自定义类,那么你应该添加这些方法).因此,typePlace在使用之前强制转换为unicode字符串:

return unicode(unicode(self.typePlace) + " " + self.name)
Run Code Online (Sandbox Code Playgroud)