Created
October 25, 2022 04:31
-
-
Save iisaka51/de492b95fe36df7369534a6a2ec4bf34 to your computer and use it in GitHub Desktop.
namedtuple cannot overwrite __init__()
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
In [18]: from typing import NamedTuple | |
...: | |
...: try: | |
...: class User(NamedTuple): | |
...: id: int | |
...: name: str | |
...: age: int | |
...: belongs: str | |
...: | |
...: def __init__(self, profile): | |
...: d = dict(profile) | |
...: self.id = d['id'] | |
...: self.name = d['name'] | |
...: self.age = d['age'] | |
...: self.belongs = d['belongs'] | |
...: | |
...: except AttributeError as e: | |
...: print(e) | |
...: | |
Cannot overwrite NamedTuple attribute __init__ | |
In [19]: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment