A Simple clipboard tool for Python (2.7+ and 3.4+) pickled objects.
If you're using Linux, be sure to install pyperclip's dependency, xclip:
sudo apt-get install xclip
Then, install via pip:
pip install pickleclip
Using pickleclip
is as simple as copying and pasting text:
In [1]: import pickleclip as picklec
In [2]: picklec.copy({'hello': 'world'})
In [3]: picklec.paste()
Out[3]: {'hello': 'world'}
To copy functions or any object that the native pickle package can't handle, use dillcopy/dillpaste (it'll use dill instead of pickle):
In [1]: import pickleclip as picklec
In [2]: def add(x, y):
...: return x + y
In [3]: picklec.dillcopy(add)
In [4]: picklec.dillpaste()
Out[4]: <function __main__.add>
In [5]: picklec.dillpaste()(5, 10)
Out[5]: 15
Pickleclip will copy any python object supported by pickle (or dill) into your clipboard. You can paste it anywhere you'd like (in another shell, for instance), as long as you use the pickleclip.paste
function.
To get Python 3 objects to unpickle on Python 2, specify protocol=2
when copying. Although pickle will try to map the new Python 3 names to the old module names used in Python 2, so that the pickle data stream is readable with Python 2, this does not come without limitations.
Going from Python 2 to Python 3 is even less trivial, and will mostly only work for the simplest cases. See also pickle-compat.
By default, the highest pickle protocol available to the interpreter is used. The higher the protocol used, the more recent the version of Python needed to read the pickle produced.
In [1]: import pickleclip as picklec
In [2]: picklec.copy({'hello': 'world'}, protocol=2)
In [1]: import pickleclip as picklec
In [2]: picklec.paste()
Out[2]: {'hello': 'world'}
It should work fine with basic objects (str, int, float, list, set, dict...), but it won't work with nothing too "fancy", (functions, custom objects...).