[Python-ideas] Add pathlib.Path.write_json andpathlib.Path.read_json
Nick Timkovich
prometheus235 at gmail.com
Wed Mar 29 17:03:19 EDT 2017
>
> I attended a talk at PYCON UK that talked to the point of using object
> composition
> rather then rich interfaces. I cannot recall the term that was used to
> cover this idea.
>
>
Separating things by concern/abstraction (the storage vs. the
serialization) results in easier-to-learn code, *especially* incrementally,
as you can (for example) plug reading from a file, a socket, a database
into the same JSON, INI, XML... functions.
Learn N ways to read data, M ways to transform the data, and you can do N*M
things with N+M knowledge. If the libraries start tightly coupling
everything, you need to start going through N*M methods, then do it
yourself anyways, because reader X doesn't support new-hotness-format Y
directly.
Perhaps less code could result from making objects "quack" alike, so
instead of you doing the plumbing, the libraries themselves would. I
recently was satisfied by being able to exchange
with open('dump.txt') as f:
for line in f:...
with
import gzip
with gzip.open('dump.gz', 'rt') as f:
for line in f:...
and it just worked through the magic of file-like objects and context
managers.
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170329/c4a696bb/attachment-0001.html>
More information about the Python-ideas
mailing list