我有以下带有 kwargs init 的父类:
class A(object):
""" Parent class """
def __init__(self, **kwargs):
# connect parameters
self.host = kwargs.get('host', 'localhost')
self.user = kwargs.get('user', None)
self.password = kwargs.get('password', None)
def connect(self):
try:
self.ConnectWithCred( self.host,
self.port,
self.user,
self.password)
except pythoncom.com_error as error:
e = format_com_message("Failed to connect")
raise Error(e)
我想创建一个“A 类”对象并调用“连接”方法。我该怎么办?我尝试了以下方法,但它无法运行(仅供参考 - 我是 Python 新手):
sub_B = A(self.host = 'example.com', self.port = 22, self.user = 'root',
self.password = 'testing')
sub_B.connect()