Python TypeError:uuu init_uuuuuuuuuuu()为关键字参数';获取了多个值;客户';
在Python TypeError:uuu init_uuuuuuuuuuu()为关键字参数';获取了多个值;客户';,python,Python,在SimilarCustomerFinder类中,我有 customer = CustomerProfile.objects.get(pk=4) ipdb> SimilarCustomerFinder(self, customer=customer, fields=self.fields) *** TypeError: __init__() got multiple values for keyword argument 'customer' 我正在与这个错误作斗争。我怎样才能修好它?如
SimilarCustomerFinder
类中,我有
customer = CustomerProfile.objects.get(pk=4)
ipdb> SimilarCustomerFinder(self, customer=customer, fields=self.fields)
*** TypeError: __init__() got multiple values for keyword argument 'customer'
我正在与这个错误作斗争。我怎样才能修好它?如果我删除
customer=customer
,我会得到***AttributeError:“CustomerUpdate表单”对象没有属性“user”
,为什么?鉴于ipdb
输出,您似乎正在尝试使用以下命令创建实例:
def __init__(self, customer, fields):
self._matches = {}
props = self.__class__.__dict__.keys()
self.customer = customer
self.fields = fields
self.checks = [k for k in props if k.startswith('check_')]
if customer:
self.user_id = customer.user.pk
else:
self.user_id = -1
for check in self.checks:
c = check.replace('+', '_')
getattr(self, c)()
但是,self
是一个隐式传递的参数,因此不应该显式传递它。像这样:
SimilarCustomerFinder(self, customer=customer, fields=self.fields)
或者,如果您真的打算显式地传递它(这会非常奇怪,并且可能没有达到您的目的-但是谁知道呢…),您必须显式地在类上调用该方法:
SimilarCustomerFinder(customer=customer, fields=self.fields)
这个代码没有意义。第一个片段中的
self
是什么?
SimilarCustomerFinder.__init__(self, customer=customer, fields=self.fields)