Functions 'knowing' other functions in a module
Terry Hancock
hancock at anansispaceworks.com
Wed Jan 22 16:03:11 EST 2003
gyro wrote:
> This approach seems very kludgy, especially the __import__('mymod')
> line. Is it necessary to 'self import' the module to carry out this
> task? Any suggestions for a better approach? I'm sure that I'm missing
> something obvious.
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
--
Anansi Spaceworks
http://www.anansispaceworks.com
More information about the Python-list
mailing list