Is there a better way of accessing functions in a module?

Kent Johnson kent at kentsjohnson.com
Tue Jun 13 16:38:21 EDT 2006


Ant wrote:
> Ant wrote:
> ...
>> But this feels like a hack... Is there a cleaner way for accessing the
>> functions of the current module similar to the __dict__ attribute of
>> classes? i.e. a way to access the local symbol table?
> 
> Sorry - posted too soon. Found the globals() built-in...

You can also
import __main__
tests = [x for x in dir(__main__) if x.endswith("test")]

for test in tests:
    getattr(__main__, test)()

but I second the suggestion of looking in to unittest or one of the 
other test frameworks.

Kent



More information about the Python-list mailing list