newbie question

Asun Friere afriere at yahoo.co.uk
Thu Nov 27 20:58:55 EST 2008


On Nov 27, 9:05 pm, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:

> The problem is that you often have more to do in the __main__ section of
> a script than just calling one simple function, and you don't
> necessarily want to pollute the module's namespace with all this code.

As I said, it's probably just me ;)  I'm not sure I understand,
however, why calling multiple functions under 'if __name__ ...' will
pollute the namespace if these functions are already defined there?

Eg.

def foo (arg) :
    #stuff
    return exit_status
def bar (arg) :
    #stuff
    return exit_status
def main (argv) :
    #parse args
    #call and do stuff with foo and bar
    return exit_status

if __name__ == '__main__' :
    import sys
    sys.exit(main(sys.argv))

Doesn't this just pollute the namespace with main()?

Surely you should be structuring the code above the test to minimise
namespace pollution.







More information about the Python-list mailing list