Skip to content

Instantly share code, notes, and snippets.

@kurogelee
Created October 8, 2018 06:56
Show Gist options
  • Save kurogelee/1b710ff1d1bda750163734286fb69126 to your computer and use it in GitHub Desktop.
Save kurogelee/1b710ff1d1bda750163734286fb69126 to your computer and use it in GitHub Desktop.
Pythonで文字列クラスを継承する方法 ref: https://qiita.com/kurogelee/items/88885733c2aba73420c8
class Log(str):
def __new__(cls, id_: str, val: str):
self = super().__new__(cls, val)
self.id: str = id_
return self
log1 = Log("id1", "test")
print(log1, log1.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment