473,804 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1864
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
2782
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. boolean options (--squibble) 3. data lines (MUNGE:x:y:z:frob)
2
3098
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 on I will try to multiply these values. When I have found the parent I will multiply with its parent and so on, all the way to the top of the xml-file. The files are pasted below. First I have tried to find these values, the next step will be...
20
3127
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 alert(a2) I will see 42 there too. I'm doubting, but I was
3
5425
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 application I have a file upload page and I wish to upload the files to the main application. I have tried this application of MapPath and it fails. string myPath = "http://main.com"
11
2538
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 database I get the result, but I want to do it in the code.
1
1205
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 create an XML, and this is to iterate through all the objects that needs to be serialized into the XML and then use toXML()-methods in each object instance that should appear in the XML. In Java, you could pass a StringBuffer which will then be
20
7863
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 numbers, multiply them, and ask you for the result. It also needs to have four responses for both right and wrong answers and should print them randomly as well. The program should use at least 2 functions. Any help would be greatly appreciated. ...
14
3270
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 struggling with a type error: The argument ROLES passed to function setRoles() is not of type array. If the component name is specified as a type of this argument, the reason for this error might be that a definition file for such component...
15
2517
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. I usually use COM as it allows very specific settings of the shortcut, such as the Working Directory and the Target Path. However, the following will not work for some reason:
0
9577
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10569
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10315
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.