This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2020-03-26 11:25 by Diego Palacios, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
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.
msg415580 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-19 22:52

This is basically a request to add API to the stdlib to turn a two-liner into a one-liner.
msg415588 - (view) Author: Grégory Starck (gstarck) * Date: 2022-03-20 02:41
FWIW -1 as well, for same reasons.
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84255
2022-03-20 03:45:30serhiy.storchakasetstatus: open -> closed
resolution: rejected
stage: resolved
2022-03-20 02:41:40gstarcksetnosy: + gstarck
messages: + msg415588
2022-03-19 22:52:33iritkatrielsetnosy: + iritkatriel
messages: + msg415580
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