Code Monkey home page Code Monkey logo

pickleclip's Introduction

Pickleclip

PyPI version Build Status Coverage Status Code Health

A Simple clipboard tool for Python (2.7+ and 3.4+) pickled objects.

Installation

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

Usage:

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.

Copying from Python 3 to Python 2 using pickle

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.

Python 3 shell:
In [1]: import pickleclip as picklec

In [2]: picklec.copy({'hello': 'world'}, protocol=2)
Python 2 shell:
In [1]: import pickleclip as picklec

In [2]: picklec.paste()
Out[2]: {'hello': 'world'}

Copying from different Python versions using dill

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...).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.