简体   繁体   English

TypeError:__ init __()得到关键字参数'customer'的多个值

[英]TypeError: __init__() got multiple values for keyword argument 'customer'

customer = CustomerProfile.objects.get(pk=4)
ipdb> SimilarCustomerFinder(self, customer=customer, fields=self.fields)
*** TypeError: __init__() got multiple values for keyword argument 'customer'

In SimilarCustomerFinder class, I have SimilarCustomerFinder类中,我有

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)()

I am struggling with this error. 我正在努力解决这个错误。 How could I fix it? 我该怎么办呢? If I remove customer=customer , I got *** AttributeError: 'CustomerUpdateForm' object has no attribute 'user' , why? 如果我删除customer=customer ,我得到*** AttributeError: 'CustomerUpdateForm' object has no attribute 'user' ,为什么?

Given the ipdb output it seems like you're trying to create an instance using this command: 鉴于ipdb输出,您似乎正在尝试使用此命令创建实例:

SimilarCustomerFinder(self, customer=customer, fields=self.fields)

However self is an implicitly passed argument so you shouldn't pass it in explicitly. 但是self是一个隐式传递的参数,所以你不应该明确地传递它。 Like this: 像这样:

SimilarCustomerFinder(customer=customer, fields=self.fields)

Or if you really intended to pass it in explicitly (which would be really weird and probably doesn't do what you intend - but who knows ...) you have to call the method explicitly on the class: 或者,如果你真的打算明确地传递它(这可能非常奇怪,可能不会按照你的意图 - 但谁知道......)你必须在类上显式调用该方法:

SimilarCustomerFinder.__init__(self, customer=customer, fields=self.fields)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:__init __()为关键字参数“ choices”获得了多个值 - TypeError: __init__() got multiple values for keyword argument 'choices' TypeError:“ __ init __()为关键字参数'name'获得了多个值” - TypeError: “__init__() got multiple values for keyword argument 'name'” TypeError:__init __()获得了意外的关键字参数'customer - TypeError: __init__() got an unexpected keyword argument 'customer TypeError:__init__() 在 Santander 客户交易数据库中为参数“评分”获得了多个值 - TypeError: __init__() got multiple values for argument 'scoring' at Santander Customer Transaction database 在Scrapy中使用规则和请求会引发异常TypeError:__init __()为关键字参数'callback'获得了多个值 - Using Rules and Requests in Scrapy throws exception TypeError: __init__() got multiple values for keyword argument 'callback' TypeError at '' __init__() 得到一个意外的关键字参数 '' - TypeError at '' __init__() got an unexpected keyword argument '' / __init __()的Django Rest Framework TypeError为关键字参数'read_only'获取了多个值 - Django Rest Framework TypeError at / __init__() got multiple values for keyword argument 'read_only' __init__() 为关键字参数“列”获得了多个值 - __init__() got multiple values for keyword argument 'columns' windrose:__init __()获得了多个关键字参数值 - windrose: __init__() got multiple values for keyword argument __init __()为关键字参数“ bar”获得了多个值 - __init__() got multiple values for keyword argument 'bar'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM