たくさん入力せずにスーパークラスのインスタンスを使用してサブクラスを定義するにはどうすればよいですか?参照:より少ないキーストロークでサブクラス化
class A():
def __init__(self,x,y):
self.x=x
self.y=y
class B(A):
def __init__(self,x,y,z):
A.__init__(A,x,y)
self.z=z
class1=A(2,3)
class2=B(class1.x,class1.y,5) # Is there something easier than this, where I don't have to type class1.x, class1.y and
# I can just pass all the data members of class1 at once?
あの、 'クラス2 = B(2,3,5)'? –
xやy、z..foobar、quxxなどの文字列があれば、シーケンスなどを使用している可能性があります。kwargsもパスとして使用されることがあります(明快さと直接的に結合されたパラメータを犠牲にして)、それはどのようにうまくいくように見えますか? – user2864740
この具体例では、 'A'のインスタンスを' B .__ init __() 'に渡すことができます。 –