[BangPypers] Packing string and character

Anand Balachandran Pillai abpillai at gmail.com
Sun May 30 07:56:07 CEST 2010

On Sat, May 29, 2010 at 8:19 PM, Noufal Ibrahim <noufal at gmail.com> wrote:

> On Sat, May 29, 2010 at 4:26 PM, Gaurav Kalra <gvkalra at gmail.com> wrote:
> > Hi Noufal.
> >
> > >From Wikipedia:
> > JSON only handle basic Python types like strings, integers, and
> > collections of basic types, whereas pickle is intended for arbitrary
> > objects.
> >
> > pickle won't be more suitable for what Murugadoss is asking for ?
> For general purpose serialisation, json is better. Pickle is a Python
> specific format that will necessitate that the remote end be Python
> (or atleast have a sawn off depickler). Also, unpickling involves
> something like execution and the data is to be treated as malicious
> (check out the warning here -
> http://docs.python.org/library/pickle.html).  JSON has no such issues
> since it's just data . With JSON, the remote end is free to be in
> whatever language you want which is a good thing.
> It is possible to jsonify arbitrary types but you'll have to decide
> how. I'm not sure there's much point in serialising code itself and
> sending it across a line. Well, maybe for something like an RPC
> mechanism but even then, it shouldn't be code but some data
> representing an instruction of some kind.

 I use a few thumb rules when deciding between JSON and Pickle.

 1. If data is to be persisted to disk and not sent out to network,
  use Pickle, especially when only a Python runtime is involved.
 2. If the data has to be portable not just across Python runtimes,
  use JSON.

 Finally if I dont have much time to decide what the data
 format should be in terms of portability, safety etc, I always
  default to JSON, since that is generally safer.

> --
> ~noufal
> http://nibrahim.net.in.

> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers


More information about the BangPypers mailing list