Skip to content

第八章8.6及8.8更改 #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/c08/p06_create_managed_attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Properties还是一种定义动态计算attribute的方法。

@property
def diameter(self):
return self.radius ** 2
return self.radius * 2

@property
def perimeter(self):
Expand Down
4 changes: 2 additions & 2 deletions source/c08/p08_extending_property_in_subclass.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
----------
在子类中扩展一个property可能会引起很多不易察觉的问题,
因为一个property其实是 ``getter``、``setter`` 和 ``deleter`` 方法的集合,而不是单个方法。
因此,但你扩展一个property的时候,你需要先确定你是否要重新定义所有的方法还是说只修改其中某一个。
因此,当你扩展一个property的时候,你需要先确定你是否要重新定义所有的方法还是说只修改其中某一个。

在第一个例子中,所有的property方法都被重新定义。
在每一个方法中,使用了 ``super()`` 来调用父类的实现。
Expand Down Expand Up @@ -135,7 +135,7 @@
.. code-block:: python

class SubPerson(Person):
@Person.getter
@Person.name.getter
def name(self):
print('Getting name')
return super().name
Expand Down