The correct way to do this is:
def mything(a, b, c=None):
""" do something, like check if 'c' is not None """
print a, b, c
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.
- and -
mything(1, 2, 3)
will both work.
[mailto:email@example.com]On Behalf Of Tom
Sent: Wednesday, April 04, 2001 12:22 PM
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:
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:
I get an error message like: "not enough arguments; expected 3 got 2".
I've overcome this by using a single method like:
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 Whittaker (firstname.lastname@example.org)
University of Wisconsin-Madison
Space Science and Engineering Center
Jython-users mailing list