Title: pickle module dump and load: add support for string file names
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Diego Palacios, eric.smith
Priority: normal Keywords:

Created on 2020-03-26 11:25 by Diego Palacios, last changed 2020-03-26 22:31 by Diego Palacios.

Messages (3)
msg365061 - (view) Author: Diego Palacios (Diego Palacios) Date: 2020-03-26 11:25
The pickle functions dump and load are often used in the following lines:

import pickle

fname = '/path/to/file.pickle'

with open(fname, 'rb') as f:
    object = pickle.load(f)

The load function should also accept a file name (string) as input and automatically open and load the object. The same should happen for the dump function. This would allow a simple use of the functions:

object = pickle.load(fname)

This is what many users need when reading and storing and object from/to a file.
msg365065 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-03-26 12:42
I think it's a bad design to overload a function based on the type of am argument. I realize the stdlib does this in a number of places, for older functions. I don't think we'd add such a function today.

I might not object to a new pickle API to do this, but I think the best approach is to have your own wrapper function.
msg365115 - (view) Author: Diego Palacios (Diego Palacios) Date: 2020-03-26 22:31
In this case two new functions should be added to the pickle function. I think they would be very useful and many users would make use of them.
Date User Action Args
2020-03-26 22:31:43Diego Palaciossetmessages: + msg365115
2020-03-26 12:42:15eric.smithsetnosy: + eric.smith
messages: + msg365065
2020-03-26 11:25:16Diego Palacioscreate