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 | |
| @dataclass | |
| class Employee(object): | |
| id: int | |
| name: str | |
| if __name__ == '__main__': | |
| emp = Employee(1,"Talha Gillani") | |
| emp2= Employee(100,"Syed Talha Gillani") | |
| print("emp:{}".format(emp)) |
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
| import requests | |
| from dataclasses import dataclass,field | |
| from dateutil import parser | |
| from datetime import datetime | |
| # GithubAPIWrapper | |
| @dataclass | |
| class GithubWrapper(object): | |
| login: str | |
| id: int | |
| node_id: str |
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
| import requests | |
| from dateutil import parser | |
| from datetime import datetime | |
| # GithubAPIWrapper | |
| class GithubWrapper(object): | |
| def __init__(self,login: str, | |
| id: int, | |
| node_id: str, | |
| avatar_url: str, | |
| gravatar_id: str, |
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 | |
| from typing import Any | |
| @dataclass | |
| class Customer(object): | |
| customer_id: Any = 2.0 | |
| name: str = "" | |
| @dataclass | |
| class CustomerExtended(Customer): | |
| address: str = "" | |
| customer_id: int = 1 |
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") |
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(frozen=True,order=True) | |
| class Employee(object): | |
| id: int = field(compare=True) | |
| name: str = field(compare=False) | |
| salary: int = field(compare=True) | |
| if __name__ == '__main__': | |
| emp = Employee(1,"Talha Gillani",5000) | |
| emp2= Employee(100,"Syed Talha Gillani",10000) |
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 | |
| @dataclass(frozen=True,order=True) | |
| class Employee(object): | |
| id: int | |
| name: str | |
| salary: int | |
| if __name__ == '__main__': | |
| emp = Employee(1,"Talha Gillani",5000) | |
| emp2= Employee(100,"Syed Talha Gillani",10000) |
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 | |
| @dataclass(frozen=True) | |
| class Employee(object): | |
| id: int | |
| name: str | |
| if __name__ == '__main__': | |
| emp = Employee(1,"Talha Gillani") | |
| emp2= Employee(100,"Syed Talha Gillani") |
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 | |
| @dataclass | |
| class Employee(object): | |
| id: int | |
| name: str | |
| if __name__ == '__main__': | |
| emp = Employee(1,"Talha Gillani") | |
| emp2= Employee(2,"Syed Talha Gillani") | |
| print("emp:{}".format(emp)) |
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 Employee(object): | |
| #Constructor | |
| def __init__(self,id:int,name:str)->None: | |
| self.id = id | |
| self.name = name | |
| #info we get when we say print(e) # e = Employee(id,name) | |
| def __repr__(self): | |
| return f'Employee(id={self.id!r},name={self.name!r})' | |