The Marshal module exists primarily to support reading and writing “pseudo-compiled” code for Python modules in .pyc files. This module does not support all types of Python objects.
The following types are supported: booleans, integers, floating point numbers, complex numbers, strings, bytes, byte arrays, tuples, lists, sets, freezes, dictionaries and code objects, where it should be understood that tuples, lists, sets, freezes, and dictionaries are supported only as long as the values they contain are supported. The singletones None, Ellipsis and StopItate can also be marshaled and parsed.
Functions :
example
# Python code to demonstrate serialization
import marshal
data = { 12 : `twelve` , `feep` : list ( `ciao` ), 1.23 : 4 + 5j ,
( 1 , 2 , 3 ): u `wer` }
bytes = marshal.dumps (data)
print bytes
Exit
{tfeep [tctitatog®Gáz®ó? y @@ ittwelve (iiiuwer0}
example
# Python code to demonstrate deserialization
import marshal
data = { 12 : `twelve` , `feep` : list ( `ciao` ), 1.23 : 4 + 5j ,
( 1 , 2 , 3 ): u `wer` }
bytes = marshal.dumps (data)
redata = marshal.loads (bytes)
print redata
Exit
{12: `twelve`, 1.23: (4 + 5j ), `feep`: [` c`, `i`,` a`, `o`], (1, 2, 3): u`wer`}
This article is provided by Aditi Gupta . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you`d like to share more information on the topic discussed above.