Created
July 10, 2018 14:31
-
-
Save tal95shah/7ab304f91e5ffccf4ee498657d8e83db to your computer and use it in GitHub Desktop.
Post-Init method of a dataclass --- Called after __init__ is called.
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
| from dataclasses import dataclass,field | |
| @dataclass | |
| class Employee(object): | |
| id: int = field(compare=True) | |
| name: str = field(compare=False) | |
| salary: int = field(compare=True) | |
| def __post_init__(self): | |
| self.name=self.name.upper() | |
| print("post_init() called") | |
| if __name__ == '__main__': | |
| emp = Employee(1,"Talha Gillani",5000) | |
| print(emp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment