This is a discussion on Re: Can you use -getattr- to get a function in the current module? - Python ; Alex, Gabriel, Thanks for the reply. Works great! On 9/3/07, Gabriel Genellina <gagsl-py2@yahoo.com.ar> wrote: > En Mon, 03 Sep 2007 20:13:43 -0300, Sergio Correia > <sergio.correia> escribi�: > > > # Module spam.py > > > > import eggs > ...
Alex, Gabriel,
Thanks for the reply. Works great!
On 9/3/07, Gabriel Genellina <gagsl-py2@yahoo.com.ar> wrote:
> En Mon, 03 Sep 2007 20:13:43 -0300, Sergio Correia
> <sergio.correia> escribi�:
>
> > # Module spam.py
> >
> > import eggs
> >
> > print getattr(eggs, 'omelet')(100)
> >
> > That is, I just call the function omelet inside the module eggs and
> > evaulate it with the argument 100.
> >
> > But what if the function 'omelet' is in the module where I do the
> > getattr (that is, in spam.py). If I do any of this
>
> Use globals():
>
> print globals()['omelet'](100)
>
> (Of course this only makes sense when using a variable instead of
> 'omelet'...)
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list