Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Created December 23, 2022 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandanote-info/b5a63374d118bbfd5513f115d846acc4 to your computer and use it in GitHub Desktop.
Save pandanote-info/b5a63374d118bbfd5513f115d846acc4 to your computer and use it in GitHub Desktop.
classmethodデコレータを使ったコンストラクタのオーバーライドの例
# See https://pandanote.info/?p=9956 for details.
class Expense:
amount = 0
reason = ""
remark = ""
def __init__(self, amount, reason, remark):
self.amount = amount
self.reason = reason
self.remark = remark
@classmethod
def no_remark(cls, amount, remark):
return cls(amount, "", remark)
@classmethod
def copy(cls, expense):
return cls(expense.amount, expense.reason, expense.remark)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment