How to call script in interative status

Steven Taschuk staschuk at telusplanet.net
Thu Feb 27 13:19:41 EST 2003


Quoth Fu Chen:
> Hi!
> 
> I use python under windows2k. 
> Uptonow i only call script by 
> python script.py arg1 arg2
> 
> My question is can we call a script under the interative status ( >>>
> ) and how to do ? it seems possible to import a script and call its
> function like script.func, but how to run the segment marked by name
> == '__MAIN__' ?

Usually the best thing is to write the script like this:

    def do_something():
        ...
    if __name__ == '__main__':
        do_something()

Then it can be run programmatically by importing it and calling
do_something.

Alternatively, there's all the process management functions in the
os module.

-- 
Steven Taschuk                                7\ 7'Z {&~         .
staschuk at telusplanet.net                        Y r          --/hG-
                                            (__/ )_             1^1`





More information about the Python-list mailing list