Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:如何创建派生类的初始值设定项_Python_Constructor - Fatal编程技术网

Python:如何创建派生类的初始值设定项

Python:如何创建派生类的初始值设定项,python,constructor,Python,Constructor,我有一个类order\u order: class order_order(osv.osv): _inherit = "sale.order" _columns = { 'order_completed_date' : fields.char('Order Completed Date'), . . . } 基于SO post,我编写了以下初始值设定项: def __init__(self, **kwa

我有一个类
order\u order

class order_order(osv.osv):

    _inherit = "sale.order"

    _columns = {
        'order_completed_date' : fields.char('Order Completed Date'),
        .
        .
        .
    }
基于SO post,我编写了以下初始值设定项:

def __init__(self, **kwargs):
    super(order_order, self).__init__(**kwargs)
    self.order_completed_date = order_completed_date
    .
    .
    .
我正在尝试将对象创建为:

order_order.__new__(order_completed_date=order_completed_date, ...)
但我得到了以下错误:

TypeError: __new__() got an unexpected keyword argument 'order_completed_date'
编辑:获得与以下内容相同的错误:

order_order(order_completed_date=order_completed_date, ...)
EDIT2: 完全错误:

Traceback (most recent call last):
  File "/home/nish/repos/stage/openerp/web/addons/web/http.py", line 292, in dispatch
    r = method(self, **self.params)
  File "/home/nish/repos/stage/openerp/web/addons/web/controllers/spree_api.py", line 118, in some_html
    order_order(order_completed_date=order_completed_date, order_id=order_id, product_id=product_id, product_name=product_name, size=size, product_cost_cp=product_cost_cp, product_cost_sp=product_cost_sp, product_cost_mrp=product_cost_mrp, product_creation_date=product_creation_date, product_taxon=product_taxon, user_email=user_email, user_name=user_name, user_address=user_address, user_city=user_city, city_zip_code=city_zip_code, user_state=user_state, user_country=user_country)
TypeError: __new__() got an unexpected keyword argument 'user_address'
我做错了什么?
如何更正错误?

\uuuuuu new\uuuuu
是类型的构造函数,您通常不希望这样使用它。创建对象(还包括调用其初始化器)的常规方法如下:

order_order(order_completed_date=order_completed_date, ...)

所以,只需调用类型;调用的参数将被传递给初始化器。

我是否需要更改基类的初始化器?能否显示完整的错误消息?同样的错误不太可能发生(因为您不再明确地调用
\uuuuu new\uuuu
);但也有可能将关键字参数传递给基类型。您可能不应该将关键字参数传递给基的
\uuuuu init\uuuuuuuuuu
。好吧,在文件
spree\u api.py
的第119行,您仍然在调用
order\u order.\uu new\uuuuuuuuuuuuuuuu(…)
。抱歉,我复制了旧的回溯。请你再看看。即使没有新的,我也会遇到同样的错误。我也尝试了
super(order\u order,self)。\uuu init\uuu()
。但同样