A Newbie Question: How To Call Other Python Programs From A Main Python Program.

Alex Martelli aleaxit at yahoo.com
Mon Dec 11 11:52:15 EST 2000


<jbranthoover at my-deja.com> wrote in message
news:912tpb$efl$1 at nnrp1.deja.com...
> Hello All,
> I have written several small Python programs.  These programs
> are not just functions but complete programs with their own menuing
> systems.
>
>         My question is,  how do I (and is it a good idea) call these
> independent Python programs from one main program that selects which
> program to run from a main menu?  I tried to use the import command.
> This seems to work OK except that the programs only run once.  If the
> same program is selected from the menu,  nothing happens.  It seems to
> return immediately without running the program.

If the module has already been imported, then you need to
call the built-in function
    reload
passing to it the module-object as its only argument.

sys.modules is a dictionary of all currently loaded modules,
with the modulenames as keys, so it's not hard to check if
you need to import, or to reload.


Alex








More information about the Python-list mailing list