how do i pack and unpack messages in python?

Randall Hopper aa8vb at yahoo.com
Thu Apr 20 10:07:06 EDT 2000


Shaun:
 |so i now have a message that looks like:
 |
 |id                       : 10
 |subid                  :13
 |NV sequence :   {14, "shaun"-string
 |                         {20, ["Anytown, Anywhere"]-list
 |                         {34, 1234567890-int
 |
 |
 |i want to pack the message to look like this:
 |
 |10 fs 13 fs 14 fs s shaun fs 20 fs l s anytown fs s anywhere fs i 1234567890
 |gs gs
 |
 |(NV=Name Value Pair, fs=field seperator, s=string, i=int, l=list, group
 |seperator)
 |
 |can anyone please tell me how id go about manipulating the strings so as i
 |can join them using field seperators, any ideas anyone, or even tell me
 |where i might find out how to do this problem.

I was going to mention the struct, array, or xdrlib modules to you, but
from your desired output format (all ASCII it appears), it looks like
a simple string.join would do the job:

   >>> import string
   >>> string.join( [ str(10), str(13), str(14), str("shaun") ], ";" )
   '10;13;14;shaun'

   etc.

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list