Select one of 2 functions with the same name ?

Francesco Guerrieri f.guerrieri at gmail.com
Sun Jun 10 13:11:19 EDT 2007


If the functions are
f1, f2, f3  you could go this way:

def SimulationRun():
    if simulation_level = 1: SimulationFunction = f1
    else if simulation_level = 2: SimulationFunction = f2
    else ....


and in the rest of the code you can refer to SimulationFunction
instead of explicitly calling f1, f2 or f3.

I'm sure that there are many smarter methods :-)



On 6/10/07, Stef Mientki <S.Mientki-nospam at mailbox.kun.nl> wrote:
> hello,
>
> For a simulation at different levels,
> I need different functions with the same name.
> Is that possible ?
>
> I can realize it with a simple switch within each function,
> but that makes the code much less readable:
>
> def Some_Function():
>    if simulation_level == 1:
>      ... do things in a way
>    elif simulation_level == 2:
>      ... do things in another way
>    elif simulation_level == 3:
>      ... do things in yet another way
>
>
> thanks,
> Stef Mientki
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as
both victim and villain by the vicissitudes of fate. This visage, no
mere veneer of vanity, is a vestige of the vox populi, now vacant,
vanished. However, this valorous visitation of a bygone vexation
stands vivified, and has vowed to vanquish these venal and virulent
vermin vanguarding vice and vouchsafing the violently vicious and
voracious violation of volition. The only verdict is vengeance; a
vendetta held as a votive, not in vain, for the value and veracity of
such shall one day vindicate the vigilant and the virtuous. Verily,
this vichyssoise of verbiage veers most verbose vis-à-vis an
introduction, so let me simply add that it's my very good honor to
meet you and you may call me V." -- V's introduction to Evey



More information about the Python-list mailing list