June 2019
Beginner to intermediate
770 pages
19h 24m
English
In order to work with persistence, we need some objects that we want to save. We'll look at a simple microblog and the posts on that blog. Here's a class definition for Post:
from dataclasses import dataclassimport datetime@dataclassclass Post: date: datetime.datetime title: str rst_text: str tags: List[str] def as_dict(self) -> Dict[str, Any]: return dict( date=str(self.date), title=self.title, underline="-" * len(self.title), rst_text=self.rst_text, tag_text=" ".join(self.tags), )
The instance variables are the attributes of each microblog post – a date, a title, some text, and some tags. Our attribute name provides us with a hint that the text should be in reStructuredText(reST) markup, even though ...
Read now
Unlock full access