elementary tuple question. (sorry)

S

Steven W. Orr

I have a tuple that I got from struct.unpack. Now I want to pass the data
from the returned tuple to struct.pack
Traceback (most recent call last):
File "<stdin>", line 1, in ?
struct.error: required argument is not an integer

What's the idiom to pass the data in tup?

TIA

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
 
A

attn.steven.kuo

I have a tuple that I got from struct.unpack. Now I want to pass the data
from the returned tuple to struct.pack


'l 10l 11i h 4h c 47c 0l'>>>struct.pack(fmt, tup)

Traceback (most recent call last):
File "<stdin>", line 1, in ?
struct.error: required argument is not an integer

What's the idiom to pass the data in tup?


Try

mystring = struct.pack(fmt, *tup)
 
7

7stud

I have a tuple that I got from struct.unpack. Now I want to pass the data
from the returned tuple to struct.pack


'l 10l 11i h 4h c 47c 0l'>>>struct.pack(fmt, tup)

Traceback (most recent call last):
File "<stdin>", line 1, in ?
struct.error: required argument is not an integer

What's the idiom to pass the data in tup?

TIA

import struct

fmt = "l l"
result = struct.pack(fmt, 12, 4)

t = (12, 4)
result = struct.pack(fmt, *t)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top