Skip to content

Instantly share code, notes, and snippets.

@Chestermozhao
Created July 8, 2020 08:15
Show Gist options
  • Save Chestermozhao/011d6f787488f669d5460a349cbecae3 to your computer and use it in GitHub Desktop.
Save Chestermozhao/011d6f787488f669d5460a349cbecae3 to your computer and use it in GitHub Desktop.
from dataclasses import dataclass, asdict
import datetime
@dataclass
class AccountRecord:
consumption: int
event: str
date: datetime.datetime
today = datetime.datetime.now()
record = AccountRecord(100, "lunch", today)
print(record)
record_dict = asdict(record)
print(record_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment