Created
July 8, 2020 07:59
-
-
Save Chestermozhao/1ac99dc7b99793cae4cb55b61614d786 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cached_property import cached_property | |
class Monopoly(object): | |
def __init__(self): | |
self.boardwalk_price = 500 | |
@cached_property | |
def boardwalk(self): | |
# using example from cached_property pypi document | |
# no matter times you calling this method, it's just execute once | |
# so, print just once and price just add once | |
print("======hello world======") | |
self.boardwalk_price += 50 | |
return self.boardwalk_price | |
monopoly = Monopoly() | |
print(monopoly.boardwalk) | |
print(monopoly.boardwalk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment