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

Sergio Boix Moriano smoriano at sicon.net
Mon Dec 11 12:10:01 EST 2000


             A Newbie Question: How To Call Other Python Programs From A Main Python Program.
        Date:
             Mon, 11 Dec 2000 16:01:52 GMT
       From:
             jbranthoover at my-deja.com
 Organization:
             Deja.com - Before you buy.
         To:
             python-list at python.org
 Newsgroups:
             comp.lang.python



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.

        Any information that you can give me will be greatly
appreciated.  Thank you for your time.

      If you´re working under windowsx, nt and  sample code will be

            import win32con, win32api
            guion='executable arguments'
            #    The executable will be either the program or the python executable
            #  with  the .py file as an argument. Tis is:
            # guion='mypy.exe args'
            # or guion='python.exe mypy.py args'

           show=win32con.SW_SHOWNORMAL
           cad1 = win32api.WinExec(guion, show)

        You can use this way

                    import os
                    os.popen('executable','r')

        With this code you have a multiplattform code (it works in winblows, linux, mac, etc)

    Regards





More information about the Python-list mailing list