creating multiply arguments for a method.

noro amit.man at gmail.com
Mon Aug 28 09:12:36 EDT 2006


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




More information about the Python-list mailing list