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 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)]))
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
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
> > 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.
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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,
-> ...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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?
|
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")...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |