def method with variable no of parameters file.writeStuff(n, a1, a2,

alex23 wuwei23 at
Mon Apr 5 01:19:39 CEST 2010

"vlad_fig" <vlad_... at> wrote:
> file.writeStuff(2,a1,a2)
> file.writeStuff(3,a1,a2,a3)
> ....
> file.writeStuff(n,a1,a2,
> ---
> so i want a method i can call based on the number of parameters
> n , and that allows me to add these extra parameters based on n

It's not necessary to have to specify the number of parameters, you
can use Python's support for optional parameters[1] instead:

  def writeStuff(self, *args):

args will be a list of the values passed into writeStuff.


More information about the Python-list mailing list