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

Stef Mientki stef.mientki at gmail.com
Sun Jul 12 09:47:27 EDT 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

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

In the library fill under construction I put this main section:
(sb_test.py 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 ( 'db_test.py', new_globals )
 




More information about the Python-list mailing list