Python2的写法用的是
def __unicode__(self):
return self.name
而python3中写法是
def __str__(self):
return self.name
本文介绍了从Python2升级到Python3时字符串方法的变化。在Python2中使用__unicode__方法返回对象名称,在Python3中则使用__str__方法实现相同功能。
Python2的写法用的是
def __unicode__(self):
return self.name
而python3中写法是
def __str__(self):
return self.name

被折叠的 条评论
为什么被折叠?
