parameter name conflict. How to solve?

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Tue Mar 8 14:38:30 CET 2005


Bo Peng a écrit :
> Dear list,
> 
> If you ask: why do you choose these names? The answer is: they need to 
> be conformable with other functions, parameter names.
> 
> I have a function that pretty much like:
> 
> def output(output=''):
>   print output
> 
> and now in another function, I need to call output function, with again 
> keyword parameter output
> 
> def func(output=''):
>   output(output=output)
> 
> Naturally, I get 'str' object is not callable. Is there a way to tell 
> func that the first output is actually a function? (like in C++, 
> ::output(output) )
> 
> Thanks.
> Bo

What I'd suggest is :

def func(output=''):
   gobals()["output"](output=output)

that way, the function resolution is still dynamic, but you explicitly 
ask for a name global and not local ...

Pierre



More information about the Python-list mailing list