问下如下代码 Python 类为啥有不同的结果?

2021-03-09 14:59:52 +08:00
 coolair
class Test(models.Model):
    name = models.CharField('名称', max_length=64, unique=True)

    def __init__(self, *args, **kwargs):
        super(Test, self).__init__(*args, **kwargs)
        print(self, type(self))    # 为啥这里 self 是空白?


class Test(object):
    def __init__(self, name):
        print(self)  # 为啥这里 self 有东西?
        self.name= name

test = Test(name='aaa')    # 输出<Test object at 0x000002A3E4016F70>
426 次点击
所在节点    问与答
1 条回复
coolair
2021-03-09 15:15:19 +08:00
我的锅,哈哈。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/759989

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX