Python object initialization bug. Or am I misunderstanding how objects work?
问题 1 import sys 2 3 class dummy(object): 4 def __init__(self, val): 5 self.val = val 6 7 class myobj(object): 8 def __init__(self, resources): 9 self._resources = resources 10 11 class ext(myobj): 12 def __init__(self, resources=[]): 13 #myobj.__init__(self, resources) 14 self._resources = resources 15 16 one = ext() 17 one._resources.append(1) 18 two = ext() 19 20 print one._resources 21 print two._resources 22 23 sys.exit(0) This will print the reference to the object assigned to one.