[Tutor] FunctionType list from ModuleType Attributes

Andy W toodles@yifan.net
Tue, 12 Feb 2002 14:05:52 +0800

> Although functions don't strictly have a name, if you need a description
> that includes the likely name (but it may be wrong), try str(f) for a
> function f.

Well I don't know just how long this has been around, but:

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> def test(n):
            print n

>>> dir(test)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__',
'__getattribute__', '__hash__', '__init__', '__name__', '__new__',
'__reduce__', '__repr__', '__setattr__', '__str__', 'func_closure',
'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals',
>>> test.func_name

Or maybe I'm misunderstanding...?

I also think Danny's suggestion of using the 'inspect' module is a good one.

Andy W.

> Easiest however would be to use a for loop over the names in dir(module),
> then you alread know what the function is called in the module.
> --
> Remco Gerlich
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor