Python 3.7 – data classes

A cool new feature made its way into Python 3.7: Data classes.

When You’ve already read my article about Lombok the concept isn’t so new at all: With the new decorator @dataclass You can save a huge amount of time because the methods

  • __init__()
  • __repr__()
  • __eq__()

are created for you!

from dataclasses import dataclass

@dataclass
class CinemaEvent:
    location: str
    url: str

my_event = CinemaEvent("Cinecitta", "https://www.cinecitta.de/de/A-Quiet-Place-4552.html")
print(my_event)

Further readings:

https://realpython.com/python-data-classes/