handling different arguments depending on first argument
Michael Gilfix
mgilfix at eecs.tufts.edu
Sat Apr 27 15:42:40 EDT 2002
Sure. Try something like this:
def my_func (*args):
mode = args.pop (0)
if mode == MODE1:
# Do mode1 stuff with remainder of args
elif mode == MODE2:
# Do mode2 stuff
else:
raise Exception
-- Mike
On Sat, Apr 27 @ 19:09, Paul Miller wrote:
> I've written a C function (callable from Python) that can take a
> variable number of arguments, and the arguments after the first are
> dependent on what the first was. For example, the signatures for 2
> "modes" might look like this:
>
> my_func(MODE1, var1, var2, var3=None)
> my_func(MODE2, var1, var2=None)
>
> etc.
>
> Is it possible to handle this kind of different calling convention in
> pure Python? I'd like to write the equivalent of an "overloaded" Python
> object constructor, which takes various arguments depending on the
> first.
> --
> http://mail.python.org/mailman/listinfo/python-list
`-> (paul)
--
Michael Gilfix
mgilfix at eecs.tufts.edu
For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html
More information about the Python-list
mailing list