473,406 Members | 2,956 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.

Using multiple "*"-style arguments

File this one under "enhancement request" I guess, but it would sure be
nice. I wrote this line the other day, thinking it would just work:

x = struct.pack(">HhhhhhhHHHL", i, *bounds, *b[0:2], *b[6:9], len(s))

Unfortunately, it doesn't. The only valid place for an "*"-style
argument is at the end of the arguments list. But this line seems so
natural! Since struct.pack expects all its arguments separately (rather
than gathered into a list or tuple), I have to be able to accommodate
its needs, and since I had several arguments already in lists, I thought
I could get away with this notation.

Certainly I can get around this limitation by either spelling out the
arguments (i.e. b[0], b[1], b[6]...), or by writing multiple lines of
code to gather the arguments into a single list which could then have
the "*" applied. But I'd love a simpler, more compact notation, not
unlike what I've written above. Does anyone know of a current Python
idiom for unravelling list arguments in calls?

Dave
Jul 18 '05 #1
5 1282
"Dave Opstad" <da*********@agfamonotype.com> wrote in message
news:da*******************************@reader0901. news.uu.net...
File this one under "enhancement request" I guess, but it would sure be
nice. I wrote this line the other day, thinking it would just work:

x = struct.pack(">HhhhhhhHHHL", i, *bounds, *b[0:2], *b[6:9], len(s))

Unfortunately, it doesn't. The only valid place for an "*"-style
argument is at the end of the arguments list. But this line seems so
natural! Since struct.pack expects all its arguments separately (rather
than gathered into a list or tuple), I have to be able to accommodate
its needs, and since I had several arguments already in lists, I thought
I could get away with this notation.


Does this do what you want?

x = struct.pack((">HhhhhhhHHHL", i, *(bounds + b[0:2] + b[6:9] +
[len(s)]))
Jul 18 '05 #2
In article <C2***************@bgtnsc05-news.ops.worldnet.att.net>,
"Andrew Koenig" <ar*@acm.org> wrote:
Does this do what you want?

x = struct.pack((">HhhhhhhHHHL", i, *(bounds + b[0:2] + b[6:9] +
[len(s)]))


No, unfortunately, because the arguments in the bounds and b lists are
numeric, so adding them isn't the right thing.

But thanks for the suggestion!
Dave
Jul 18 '05 #3
In article <C2***************@bgtnsc05-news.ops.worldnet.att.net>,
"Andrew Koenig" <ar*@acm.org> wrote:
Does this do what you want?

x = struct.pack((">HhhhhhhHHHL", i, *(bounds + b[0:2] + b[6:9] +
[len(s)]))


Wait, ignore my previous reply. Yes, I think this does work, and it fits
within the Python idiom I was seeking.

Thanks!
Dave
Jul 18 '05 #4
> > Does this do what you want?

x = struct.pack((">HhhhhhhHHHL", i, *(bounds + b[0:2] + b[6:9] +
[len(s)]))


No, unfortunately, because the arguments in the bounds and b lists are
numeric, so adding them isn't the right thing.


Have you tried it? b[0:2] is a list, so + means concatenation, not
addition.
Jul 18 '05 #5

"Dave Opstad" <da*********@agfamonotype.com> wrote in message
news:da*******************************@reader0901. news.uu.net...
File this one under "enhancement request" I guess, but it would sure be
nice. I wrote this line the other day, thinking it would just work:

x = struct.pack(">HhhhhhhHHHL", i, *bounds, *b[0:2], *b[6:9], len(s))

Unfortunately, it doesn't. The only valid place for an "*"-style
argument is at the end of the arguments list. But this line seems so
natural! Since struct.pack expects all its arguments separately (rather
than gathered into a list or tuple), I have to be able to accommodate
its needs, and since I had several arguments already in lists, I thought
I could get away with this notation.

Certainly I can get around this limitation by either spelling out the
arguments (i.e. b[0], b[1], b[6]...), or by writing multiple lines of
code to gather the arguments into a single list which could then have
the "*" applied. But I'd love a simpler, more compact notation, not
unlike what I've written above. Does anyone know of a current Python
idiom for unravelling list arguments in calls?
While I haven't tested it, I suspect that this might work:

x = struct.pack("....", *[i] + bounds + b[0:2] + b[6:9] + [len(s)])

John Roth
Dave

Jul 18 '05 #6

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

Similar topics

3
by: Phil Powell | last post by:
Has anyone here ever done a case where you have a select multiple form element and you have to do both server-side and client-side validation? I am honestly not sure how to do it in Javascript (I...
0
by: Justin | last post by:
Hi. I decided to tidy up some of my queries, but I came across something that stumpt me: mysql> SELECT -> jobs.jobId, -> jobs.active, -> jobs.title, -> jobs.listed, -> ...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
1
by: Holger (David) Wagner | last post by:
Hi there, we have an application which is built with several ASCX controls some of which contain form elements (e.g. Textboxes, Buttons etc.) For example: in the top section (one...
5
by: Alex Maghen | last post by:
In ASPX 2.0 with MasterPages and all that, my entire page only has one actual <FORM>. But there are several different sections of the page that provide what are functionally separate forms with...
7
by: andrewfsears | last post by:
I have a question: I was wondering if it is possible to simulate the multiple constructors, like in Java (yes, I know that the languages are completely different)? Let's say that I have a class...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
0
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have...
11
by: O.B. | last post by:
Does C# support anything like PHP's break command that optionally accepts a parameter specifying how many loops to break out of?
3
by: uma9 | last post by:
hi, the code below is used to insert a single record....i want to know how to insert multiple records using a "for" loop...please help Set connect = CreateObject ("ADODB.Connection")...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.