473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

elementary tuple question. (sorry)

I have a tuple that I got from struct.unpack. Now I want to pass the data
from the returned tuple to struct.pack
>>fmt
'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

--
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
Apr 5 '07 #1
3 2397
On Apr 5, 2:08 pm, "Steven W. Orr" <ste...@syslang.netwrote:
I have a tuple that I got from struct.unpack. Now I want to pass the data
from the returned tuple to struct.pack
>fmt

'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)

--
Hope this helps,
Steven

Apr 5 '07 #2
On Apr 5, 3:08 pm, "Steven W. Orr" <ste...@syslang.netwrote:
I have a tuple that I got from struct.unpack. Now I want to pass the data
from the returned tuple to struct.pack
>fmt

'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)
---------

The * unpacks the tuple.

Apr 5 '07 #3
On Apr 6, 5:31 am, "7stud" <bbxx789_0...@yahoo.comwrote:
On Apr 5, 3:08 pm, "Steven W. Orr" <ste...@syslang.netwrote:
I have a tuple that I got from struct.unpack. Now I want to pass the data
from the returned tuple to struct.pack
>>fmt
'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)
---------

The * unpacks the tuple.
there's an unpack().
>>struct.unpack(fmt,result)
Apr 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alastair G. Hogge | last post by:
Hello *, I'm using Python and the cgi module to retrive data from a HTML form. I'm then trying to get that information into a string. But efforts fail when I run type(foo) on my string. type()...
10
by: Carlo v. Dango | last post by:
Hello there. I have a function which as an argument takes a tuple and either returns that tuple or a mutated version of it. The problem is that tuples are imutable, hence I have to create a new...
3
by: Jinming Xu | last post by:
Sorry for the previous message. It's really a simple question and I have solved it myself. Thanks, Jinming ------------------------------------------------------------------------ Hi Folks,
15
by: Steve M | last post by:
Hello, I'm trying to figure out the index position of a tuple member. I know the member name, but I need to know the members index position. I know that if I use the statement print tuple that...
37
by: Gregor Horvath | last post by:
Hi, >>>type() <type 'list'> >>>type(('1')) <type 'str'> I wonder why ('1') is no tuple????
6
by: groups.20.thebriguy | last post by:
I've noticed that there's a few functions that return what appears to be a tuple, but that also has attributes for each item in the tuple. For example, time.localtime() returns a time.time_struct,...
2
by: Alan Isaac | last post by:
I am probably confused about immutable types. But for now my questions boil down to these two: - what does ``tuple.__init__`` do? - what is the signature of ``tuple.__init__``? These...
2
by: fabian.conrad | last post by:
Hi, sorry for the rather basic question but I've searched everywhere and don't find an answer. I want to call PyObject_CallObject from the Python C-API and pass a tuple I've created from a...
25
by: beginner | last post by:
Hi, I am wondering how do I 'flatten' a list or a tuple? For example, I'd like to transform or ] to . Another question is how do I pass a tuple or list of all the aurgements of a function to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.