Python assignment to self in constructor does not make object the same

后端 未结 4 897
日久生厌
日久生厌 2020-12-18 09:58

I am making a constructor in Python. When called with an existing object as its input, it should set the \"new\" object to that same object. Here is a 10 line demonstratio

4条回答
  •  借酒劲吻你
    2020-12-18 10:31

    __init__ is an initializer, not a constructor. You would have to mess around with __new__ to do what you want, and it's probably not a good idea to go there.

    Try

    a = b = A(1)
    

    instead.

提交回复
热议问题