Method acting on arguements passed
Diez B. Roggisch
deets at nospam.web.de
Fri May 5 08:43:20 EDT 2006
Panos Laganakos wrote:
> I want a class method to take action depending on the type of the
> arguement passed to it.
>
> ie:
> getBook(id) # get the book by ID
> getBook(name) # get the book by name
> ...
>
> Other languages use the term function/method overloading to cope with
> this. And when I googled about it seems that GvR is testing it for 3.0
> inclusion or so.
>
> I was thinking of right after the function declaration check for the
> parameter passed by isinstance() or type() and use if..elif..else to
> act.
>
> Is this the pythonic way/best practice to apply here?
google for gnosis multimethods for a clean approach.
Diez
More information about the Python-list
mailing list