Common Python terminology

Python serialization terminology tends to focus on the words dump and load. Most of the classes we're going to work with will define methods such as the following:

  • dump(object, file): This will dump the given object to a file.
  • dumps(object): This will dump an object, returning a string representation.
  • load(file): This will load an object from a file, returning the constructed object.
  • loads(string): This will load an object from a string representation, returning the constructed object.

There's no formal standard; the method names aren't guaranteed by any formal ABC inheritance or mixin class definition. However, they're widely used. Generally, the file used for the dump or load can be any file-like object.

To be useful, the file-like object must implement a short list of methods. Generally, read() and readline() are required for the load. We can, therefore, use the io.StringIO objects as well as the urllib.request objects as sources for the load. Similarly, dump places few requirements on the data source, mostly a write() method is used. We'll dig into these file object considerations next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset