Hi all,
This does not feel Pythonic. Is there a better way to do the same?
Many TIA
T
# L = [1,2,3,4,5,6, etc....]
# L can contain 'n' elements
# fmt is made up to each particular specification
if len(L) == 0:
return ''
elif len(L) == 1:
return struct.pack(fmt,L[0] )
elif len(L) == 2:
return struct.pack(fmt,L[0] , L[1])
elif len(L) == 3:
return struct.pack(fmt,L[0] , L[1], L[2])
elif len(L) == 4:
return struct.pack(fmt,L[0] , L[1], L[2], L[3])
elif len(L) == 5:
return struct.pack(fmt,L[0] , L[1], L[2], L[3], L[4])
elif len(L) == 6:
return struct.pack(fmt,L[0] , L[1], L[2], L[3], L[4], L[5])
# etc... etc... etc ... 1 1304
Tertius Cronje wrote: Hi all, This does not feel Pythonic. Is there a better way to do the same?
Many TIA T
# L = [1,2,3,4,5,6, etc....] # L can contain 'n' elements # fmt is made up to each particular specification
if len(L) == 0: return '' elif len(L) == 1: return struct.pack(fmt,L[0] ) elif len(L) == 2: return struct.pack(fmt,L[0] , L[1]) elif len(L) == 3: return struct.pack(fmt,L[0] , L[1], L[2]) elif len(L) == 4: return struct.pack(fmt,L[0] , L[1], L[2], L[3]) elif len(L) == 5: return struct.pack(fmt,L[0] , L[1], L[2], L[3], L[4]) elif len(L) == 6: return struct.pack(fmt,L[0] , L[1], L[2], L[3], L[4], L[5])
# etc... etc... etc ...
return struct.pack(fmt, *L)
Should do the trick
ola
--
--------------------------------------
Ola Natvig <ol********@infosense.no>
infoSense AS / development This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: pablo |
last post by:
Dear Newsgroupers,
The 'main' page contains a call to a function in an included file. This
function puts a html-form on the screen. Before the form gets posted (to the
'main' page) some prior...
|
by: Alexander Mahr |
last post by:
Dear Newsgroup,
I'm somehow confused with the usage of the static keyword.
I can see two function of the keyword static in conjunction with a data
member of a class.
1. The data member...
|
by: A_StClaire_ |
last post by:
annoying one. can anyone spot the issue? it appears communityCards
can't be accessed via my static function but I don't know why...
Game.h:
#pragma once
#include <vector>
#include...
|
by: Paw Pedersen |
last post by:
Is there a way to save a variabel that can be access from a static method?
I hope there would be some way to save it in memory so I don't have to save
it in a file. It's only for a few minutes the...
|
by: rmathieu |
last post by:
Hi, I want to initialize a static String array in MC++. What I want to
do is to initialize my String array like the C# way: new String
{"11", "22"} but I could not find an equivalent in MC++. The...
|
by: pauldepstein |
last post by:
Sorry in advance if this message sounds imprecise but it's difficult to
be precise when you don't really understand what's going on.
I have a class called Parameters. The default constructor...
|
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in...
|
by: Sandro Bosio |
last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long.
I'm trying to achieve the...
|
by: Joe Strout |
last post by:
One thing I miss as I move from REALbasic to Python is the ability to
have static storage within a method -- i.e. storage that is persistent
between calls, but not visible outside the method. I...
|
by: J. Cliff Dyer |
last post by:
On Thu, 2008-11-13 at 11:19 -0600, Chris Mellon wrote:
He is using an object. Specifically, he's using a function object.
Though perhaps you meant put it into a class.
Here are a few essays...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: 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...
| |