Dataclasses: Supercharge your Python code

How to use field():

  1. default_factory=<factory> :What generator to use to create that field.
  2. init=<True/False>: If the variable will be assigned during the __init__
  3. repr=<True/False>: If the variable is private to the dataclass. It is good practice to name this variable with ‘_’ in the naming. eg private_key should be _private_key .

How to use __post_init__():

Putting it all together:

  1. first_name : First name of the person
  2. last_name : Surname of the person
  3. tier : Optional membership type. If none is specified, they become a free member.
  1. start_date: A human readable timestamp for when they started their membership.
  2. renewal_date: A human readable date for when they need to renew their membership. We are using 365 days from the start of the membership.
  3. subscription_id : An auto-generated uuid.
  4. name: Full name of the member
  5. tier: What kind of membership they have.
  6. active: If they are an active member or not.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store