我是一个新手,对在python上学习OOP感到困惑。我也尝试使用super继承类,但它并没有按预期工作
这是我的密码
parent.py
class Sale(http.Controller):
def cart(self, **post):
order = request.website.sale_get_order()
....
return request.render("website_sale.cart", values)
child.py
import Sale as sale
class SaleExtend(sale):
def cart(self, **post):
if order:
# do something
....
return super(SaleExtend, self).cart(**post)
我犯了个错误
AttributeError: 'Sale (extended by SaleExtend)' object has no attribute 'order'
如果我只是正确地使用pass
,那么如何从父级获取order
值呢
或者我做错了
您既没有实例也没有类变量
order
:类变量的创建方式如下:
实例变量的创建方式如下:
函数范围变量如下所示:
见Resolution of names和Short description of the scoping rules?
相关问题 更多 >
编程相关推荐