Functions 'knowing' other functions in a module

gyro gyromagnetic at excite.com
Thu Jan 23 07:24:21 EST 2003


Terry Hancock wrote:

> Open your python interpreter, and paste the following:
> 
> def lum():
>     print 'lum'
> 
> def ataru():
>     print 'ataru'
> 
> def _enum_functions():
>     return [k for k,v in globals().items() 
>                 if type(v)==type(_enum_functions) and k[0]!='_' ]
> 
> _enum_functions()
> 
> You should see something like this:
> Python 2.2.1 (#1, Sep  7 2002, 14:34:30) 
> [GCC 2.95.4 20011002 (Debian prerelease)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> 
>>>>def lum():
> 
> ...     print 'lum'
> ... 
> 
>>>>def ataru():
> 
> ...     print 'ataru'
> ... 
> 
>>>>def _enum_functions():
> 
> ...     return [k for k,v in globals().items() 
> ...             if type(v)==type(_enum_functions) and k[0]!='_' ]
> ... 
> 
>>>>_enum_functions()
> 
> ['ataru', 'lum']
> 
> Does that help at all?
> 
> Cheers,
> Terry
> 

Yes, that helps.
Thank you.

-g





More information about the Python-list mailing list