python3-cookbook
python3-cookbook copied to clipboard
8.13小节 使用类装饰器案例未实例化
位置:
- 8.13小节 使用类装饰器案例
- pdf 270 页
当前原文:
# Example
@check_attributes(name=SizedString(size=8),
shares=UnsignedInteger,
price=UnsignedFloat)
class Stock:
def __init__(self, name, shares, price):
self.name = name
self.shares = shares
self.price = price
- 此处装饰器中
share
和price
字段未示例化,类型为<class 'type'>
。 - 此处应该实例化为
<class '__main__.UnsignedInteger'>
,即:shares=UnsignedInteger(), price=UnsignedFloat()
改正后内容:
# Example
@check_attributes(name=SizedString(size=8),
shares=UnsignedInteger(),
price=UnsignedFloat())
class Stock:
def __init__(self, name, shares, price):
self.name = name
self.shares = shares
self.price = price
望解答指正~