The xdrlib module converts between Python datatypes and Sun's external data representation (XDR), as Example 4-7 illustrates.
Example 4-7. Using the xdrlib Module
File: xdrlib-example-1.py import xdrlib # # create a packer and add some data to it p = xdrlib.Packer() p.pack_uint(1) p.pack_string("spam") data = p.get_buffer() print "packed:", repr(data) # # create an unpacker and use it to decode the data u = xdrlib.Unpacker(data) print "unpacked:", u.unpack_uint(), repr(u.unpack_string()) u.done() packed: '