how to run the "main" section of another module ?

Stef Mientki stef.mientki at
Sun Jul 12 15:47:27 CEST 2009

Stef Mientki wrote:
> hello,
> when I''m working in a library,
> and want to test some of the library functions,
> I need to switch to  a main application,
> (which has a normal main-section)
> and run that.
> If the library is simply,
> I add a main section to the library,
> so no problem.
> But if the library requires a lot of overhead,
> I want to run some main program,
> that has a main section,
> and uses my library under construction.
> So how do I call from within the library module,
> in a main section in that library module,
> a main in another module ?
> thanks,
> Stef Mientki

I just found this in one of my programs (which works but isn't very 

In the library fill under construction I put this main section:
( is the main program, that has a main section and uses the 
library under construction)

if __name__ == '__main__':
    import db_test
    new_globals = {}
    new_globals [ '__name__' ] = '__main__'
    new_globals [ '__file__' ] = 'not really valuable'
    execfile ( '', new_globals )

More information about the Python-list mailing list