how do i run another script from my python script

Mike Meyer mwm at mired.org
Thu Oct 27 15:21:29 EDT 2005


Daniel Schüle <uval at rz.uni-karlsruhe.de> writes:
> Steve already answeared to your question, regaring PHP script
> if this would be python script, you could run it by import'ing it

That's not very pythonic. Better is to provide a function in the
script to run it (say run), then run that in the script iff it's
the script is being executed:

    if __name__ == '__main__':
       run()

Then to use it from another script, you'd do something like:

     import myscript
     myscript.run()

> or maybe using threading

Launching new threads as part of the import process is
*dangerous*. There are some nasty bugs lurking there that cause things
like your import never finishing. If you need to start a thread in a
module, the approach outlined above avoids those bugs.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list