私は以下のクラスがあります。同じクラス内のクラスのインスタンスを作成し、パラメータとして同じクラスを使用
inicial = state(None,None,[1,2,5,3,4,0,6,7,8])
:私は通常、次のようにクラスのインスタンスを作成
class state(list):
def __init__(self,parent = None, path = None, *args):
list.__init__(self, *args)
self.n = len(self)
self.parent = parent
self.path = path
def neighbors(self):
lista = []
if self.__hasUp():
lista.append(state(Self,'Up',self.__swap(self.index(0),self.index(0) - 3))))
if self.__hasDown():
lista.append(state(Self,'Down',self.__swap(self.index(0),self.index(0) + 3))))
if self.__hasLeft():
lista.append(state(Self,'Left',self.__swap(self.index(0),self.index(0) - 1))))
if self.__hasRight():
lista.append(state(Self,'Right',self.__swap(self.index(0),self.index(0) + 1))))
return lista
を
私は(私は私がやっているものの全体の文脈を置けば、それはmissleadingになると思う)followinを実行する必要があります。
anotherList = []
for neighbor in inicial.neighbors():
anotherList.append(neighbor)
I J余分な属性とメソッドをほとんど持たないリストが必要です。問題は、ネイバーズメソッドのパラメータとしてそれらを作成しているオブジェクトとの間に、それ自身のイッセンスを作成するためにこのクラスが必要なことです。私はコード内のすべてのメソッドをtestetで参照していますが、期待どおりに動作しますが、この質問には必要ないと思うので、本当に長い質問になります。
私もこれをチェックしましたDeclaring a class with an instance of it inside in Python,Create static instances of a class inside said class in Python、これはClass constructor able to init with an instance of the same class objectです。しかし、私はまだそれを理解していない:(
を私はあなたが何か提案を持っているので、もし、彼らはすべての歓迎、かなり素人午前;)
、私は注意することが重要であると考え。 – krysopath