The correct way to do this is:

def mything(a, b, c=None):
 """ do something, like check if 'c' is not None """
 if c:
  print a, b, c
 else:
  print a, b

then when you call mything with either 2 or 3 arguments the runtime figures out if 'c' should be passed, if not, it uses the default value, in this case None.

mything(1, 2)
 - and -
mything(1, 2, 3)

will both work.

brian


-----Original Message-----
From: jython-users-admin@lists.sourceforge.net
[mailto:jython-users-admin@lists.sourceforge.net]On Behalf Of Tom
Whittaker
Sent: Wednesday, April 04, 2001 12:22 PM
To: jython-users@lists.sourceforge.net
Subject: [Jython-users] overloading methods


Please pardon my basic "newbie" question...I've not been able to find the
answer to this in the tutorial, in O'Reilly, or thru web searching.

I am making a .py file with a bunch of methods.  I'd like to overload (at
least) one of them, like:

def mything(a,b,c)
  print a,b,c
def mything(a,b)
  print a,b

What I've found is that only the last one in the .py file seems to be called
every time.  If I try to reference the above with:

file.mything(1,2,3)

I get an error message like: "not enough arguments; expected 3 got 2".

I've overcome this by using a single method like:

def mything(*a)

and looking at the len(a).  Since Jython does such a great job when trying to
figure out which overloaded method to use in a Java class, I thought I must be
missing something. Is there a better/preferred way to accomplish this?

Thanks ahead for your advice & guidance,

tom
--
Tom Whittaker (tomw@ssec.wisc.edu)
University of Wisconsin-Madison
Space Science and Engineering Center
Phone/VoiceMail: 608/262-2759
Fax: 608/262-5974

_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/jython-users