enhancement request: make py3 read/write py2 pickle format
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Jun 10 01:43:11 EDT 2015
On Wednesday 10 June 2015 13:57, random832 at fastmail.us wrote:
> On Tue, Jun 9, 2015, at 23:52, Steven D'Aprano wrote:
>> > For human readable serialized data, text format protocol buffers are
>> > seriously underrated. (Relatedly: underdocumented, too.)
>>
>> Ironically, literal_eval is designed to process text-format protocols
>> using
>> human-readable Python syntax for common data types like int, str, and
>> dict.
>
> "protocol buffers" is the name of a specific tool.
It is? It sounds like a generic term for, you know, a buffer used by a
protocol. I live and learn.
https://developers.google.com/protocol-buffers/docs/pythontutorial
You have to:
- write a data template, in a separate file; just don't call it a schema,
because this isn't XML;
- don't forget the technically-optional-but-recommended (and required if you
use other languages) "package" header, which is completely redundant in
Python;
- run a separate compiler over that template, which will generate Python
classes for you; just don't think that these classes are first class
citizens that you can extend using inheritance, because they're not;
- import the generated module containing those classes;
- and now you have you're very own private pickle-like format, yay!
I'm sure that this has its uses for big, complex projects, but for
lightweight needs, it seems over-engineered and unPythonic.
--
Steve
More information about the Python-list
mailing list