私はPythonで辞書オブジェクトの周りにラッパーオブジェクトを書き込もうとしています。
class ScoredList():
def __init__(self,dct={}):
self.dct = dct
list = ScoredList()
list.dct.update({1,2})
list2 = ScoredList()
list.dct.update({"hello","world"})
print list1.dct, list2.dct # they are the same but should not be!
新しいScoredListオブジェクトを作成できないようです。つまり、すべてのスコア付きリストオブジェクトが同じ基になるディクショナリを共有しているようです。どうしてこれなの?
class ScoredList2():
def __init__(self):
self.dct = {}
上記のScoredList2のコードは正常に機能します。しかし、Pythonでコンストラクターを適切にオーバーロードする方法を知りたいです。