[Tutor] How to pass arguments to struct.pack()?
prasad rao
prasadaraon50 at gmail.com
Mon Aug 3 11:24:42 CEST 2009
Hello
I am finding it difficult to pass arguments to struct.pack().
Please some one tell me how to do it.
>>> def structpack(alist):
import struct
a='%di'%len(alist)
print a
b=[a]
print alist
print b
for x in alist:
b.append(x)
arg1=b[0]
arg2=b[1:]
return struct.pack.tuple(arg1,arg2)
>>> structpack([112, 114, 97, 115, 97, 100, 97, 32, 114, 97, 111, 32, 110])
13i
[112, 114, 97, 115, 97, 100, 97, 32, 114, 97, 111, 32, 110]
['13i']
Traceback (most recent call last):
File "<pyshell#87>", line 1, in <module>
pstruct([112, 114, 97, 115, 97, 100, 97, 32, 114, 97, 111, 32, 110])
File "<pyshell#86>", line 16, in pstruct
return struct.pack.tuple(b)
AttributeError: 'builtin_function_or_method' object has no attribute 'tuple'
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090803/ec3d6df8/attachment.htm>
More information about the Tutor
mailing list