Python でオブジェクトのリストを作成しようとしています。以下のコードは、(うまくいけば) 私がやっていることを説明するはずです:
class Base(object):
@classmethod
def CallMe(self):
out = []
#another (models) object is initialised here which is iterable
for model in models:
#create new instance of the called class and fill class property
newobj = self.__class__()
newobj.model = model
out.append(newobj)
return out
class Derived(Base):
pass
次のようにクラスを初期化しようとしています。
objs = Derived.CallMe()
「objs」に、反復できるオブジェクトのリストを含めたい。
スタックトレースに次のエラーが表示されますTypeError: type() takes 1 or 3 arguments
:newobj = self.__class__()
これを行う方法はありますか、それとも問題を間違った方法で見ていますか?