Skip to content

Instantly share code, notes, and snippets.

@Chestermozhao
Created July 8, 2020 07:59
Show Gist options
  • Save Chestermozhao/1ac99dc7b99793cae4cb55b61614d786 to your computer and use it in GitHub Desktop.
Save Chestermozhao/1ac99dc7b99793cae4cb55b61614d786 to your computer and use it in GitHub Desktop.
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