June 2019
Beginner to intermediate
770 pages
19h 24m
English
One way to serialize a Python object into XML is by including a method to emit XML text. In the case of a complex object, the container must get the XML for each item inside the container. Here are two simple extensions to our microblog class structure that add the XML output capability as text:
from dataclasses import dataclass, field, asdict@dataclassclass Blog_X: title: str entries: List[Post_X] = field(default_factory=list) underline: str = field(init=False) def __post_init__(self) -> None: self.underline = "="*len(self.title) def append(self, post: 'Post_X') -> None: self.entries.append(post) def by_tag(self) -> DefaultDict[str, List[Dict[str, Any]]]: tag_index: DefaultDict[str, List[Dict[str, Any]]] ...
Read now
Unlock full access