Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the basic difference between pickle and yaml in Python?

I am naive to Python. But, what I came to know is that both are being used for serialization and deserialization. So, I just want to know what all basic differences in between them?

like image 339
nirprat Avatar asked Sep 19 '13 17:09

nirprat


1 Answers

YAML is a language-neutral format that can represent primitive types (int, string, etc.) well, and is highly portable between languages. Kind of analogous to JSON, XML or a plain-text file; just with some useful formatting conventions mixed in -- in fact, YAML is a superset of JSON.

Pickle format is specific to Python and can represent a wide variety of data structures and objects, e.g. Python lists, sets and dictionaries; instances of Python classes; and combinations of these like lists of objects; objects containing dicts containing lists; etc.

So basically:

  • YAML represents simple data types & structures in a language-portable manner
  • pickle can represent complex structures, but in a non-language-portable manner

There's more to it than that, but you asked for the "basic" difference.

like image 130
Chris Johnson Avatar answered Nov 01 '22 02:11

Chris Johnson