Last active
May 19, 2020 21:33
-
-
Save highsmallxu/611cef8f11f31f6e88b8427d420a46c8 to your computer and use it in GitHub Desktop.
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
from typing import NamedTuple | |
import collections | |
from dataclasses import dataclass | |
# regular class | |
class TransactionObject: | |
def __init__(self, sender, receiver, date, amount): | |
self.sender = sender | |
self.receiver = receiver | |
self.date = date | |
self.amount = amount | |
# named tuple from collections | |
TransactionNamedTuple = collections.namedtuple('TransactionNamedTuple',['sender','receiver','date', 'amount']) | |
# named tuple from typing class | |
class TransactionNamedTupleTyping(NamedTuple): | |
sender: str | |
receiver: str | |
date: str | |
amount: float | |
# dataclass | |
@dataclass | |
class TransactionDataClass: | |
sender: str | |
receiver: str | |
date: str | |
amount: float | |
# dataclass with slot | |
@dataclass | |
class TransactionDataClassWithSlot: | |
__slots__ = ['sender', 'amount', 'receiver', 'date'] | |
sender: str | |
receiver: str | |
date: str | |
amount: float |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment