Created
October 8, 2018 06:56
-
-
Save kurogelee/1b710ff1d1bda750163734286fb69126 to your computer and use it in GitHub Desktop.
Pythonで文字列クラスを継承する方法 ref: https://qiita.com/kurogelee/items/88885733c2aba73420c8
This file contains hidden or 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
test id1 |
This file contains hidden or 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
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