473,413 Members | 1,794 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,413 software developers and data experts.

creating multiply arguments for a method.

Hi all,

I use a method that accept multiply arguments ("plot(*args)").
so plot([1,2,3,4]) is accepted and plot([1,2,3,4],[5,6,7,8]) is also
accepted.

the problem is that i know the number of arguments only at runtime.
Let say that during runtime i need to pass 4 arguments, each is a list,
creating a set of lists and passing it to the method wont word since
the interpartor thinks it is only 1 argument the contain a reference to
a "list of lists", instede of number of arguments, each is a list.

any suggestions?
thanks
amit

Aug 27 '06 #1
3 1843
noro wrote:
Let say that during runtime i need to pass 4 arguments, each is a list,
creating a set of lists and passing it to the method wont word since
the interpartor thinks it is only 1 argument the contain a reference to
a "list of lists", instede of number of arguments, each is a list.
>>def func(*args):
.... print "got", len(args), "argument(s)"
....
>>args = [[1, 2, 3, 4], [5, 6, 7, 8]]
func(args)
got 1 arguments
>>func(*args)
got 2 arguments

</F>

Aug 27 '06 #2

noro wrote:
Hi all,

I use a method that accept multiply arguments ("plot(*args)").
so plot([1,2,3,4]) is accepted and plot([1,2,3,4],[5,6,7,8]) is also
accepted.

the problem is that i know the number of arguments only at runtime.
Let say that during runtime i need to pass 4 arguments, each is a list,
creating a set of lists and passing it to the method wont word since
the interpartor thinks it is only 1 argument the contain a reference to
a "list of lists", instede of number of arguments, each is a list.

any suggestions?
thanks
amit
Why do you want to do this? You'll have to do some
logic in your method body to determine how many
operands you have whether you explicitly pass a list or
whether you have the system break it apart into
separate parameters.

Fredrick Lund's solution, using an * parameter in the
method definition, will produce a list that you have to
pull apart in the method. Doing the same in the method
call takes a single list of all of your parameters and then
distributes it among the parameters in the definition.

I wouldn't bother with either one. Passing a list of my
real parameters as a single parameter is, in most
circumstances, easier and IMO clearer.

John Roth

Aug 27 '06 #3

John Roth wrote:
noro wrote:
Hi all,

I use a method that accept multiply arguments ("plot(*args)").
so plot([1,2,3,4]) is accepted and plot([1,2,3,4],[5,6,7,8]) is also
accepted.

the problem is that i know the number of arguments only at runtime.
Let say that during runtime i need to pass 4 arguments, each is a list,
creating a set of lists and passing it to the method wont word since
the interpartor thinks it is only 1 argument the contain a reference to
a "list of lists", instede of number of arguments, each is a list.

any suggestions?
thanks
amit

Why do you want to do this? You'll have to do some
logic in your method body to determine how many
operands you have whether you explicitly pass a list or
whether you have the system break it apart into
separate parameters.

Fredrick Lund's solution, using an * parameter in the
method definition, will produce a list that you have to
pull apart in the method. Doing the same in the method
call takes a single list of all of your parameters and then
distributes it among the parameters in the definition.

I wouldn't bother with either one. Passing a list of my
real parameters as a single parameter is, in most
circumstances, easier and IMO clearer.

John Roth
I do not have much choise. I did not wirte the module, i just use it.

thank you all for the help,
amit

Aug 28 '06 #4

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

Similar topics

4
by: Edvard Majakari | last post by:
Hi, I was wondering what would be the most elegant way for creating a Python class wrapper for a command line utility, which takes three types of arguments: 1. options with values (--foo=bar)...
2
by: Martin Pettersson | last post by:
Hi all, I'm trying to multiply parent values in xsl. The thing is that I start with a value down in the xml-structure. From that value (in my case 'qty' value) I check the parent value and later...
20
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then...
3
by: ramonred | last post by:
Hi, I have two web apps. Lets say main and admin for the sake of simplicity. admin is a web app within main (as a subdomain). So the path for admin is http://admin.main.com within the admin...
11
by: vips | last post by:
I have a string str="10*12*14" now I want the total of this value i.e. 10 multiply 12 multiply 14 how do i get it ? is there any function in vb.net to do that ?? if i put it as query to...
1
by: msaladin | last post by:
Hi all, I'd like to list some arguments for using DOM when creating an XML message. For me, there is only one way to create complex XMLs, that is using DOM. There is of course another way to...
20
by: jjmillertime | last post by:
I'm new so i apologize if this is in the wrong spot. I'm also new to programming in C and i've been searching for quite a while on how to create a program using C that will generate two random...
14
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
15
by: Mike Driscoll | last post by:
Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.