Class constructor able to init with an instance of the same class object
问题 Can python create a class that can be initialised with an instance of the same class object? I've tried this: class Class(): def __init__(self,**kwargs): print self self = kwargs.get('obj',self) print self if not hasattr(self,'attr1'): print 'attr1' self.attr1 = kwargs.pop('attr1',[]) if not hasattr(self,'attr2'): print 'attr2' self.attr2 = kwargs.pop('attr2',[]) print self self.attr1 = kwargs.pop('attr1',self.attr1) self.attr2 = kwargs.pop('attr2',self.attr2) print self.attr1 print self