How to run script from interpreter?

Joe Smith JoeSmith at bogusaddress.com
Thu Jan 18 21:43:55 EST 2001


I like to do:
if __name__ == '__main__':
    main( sys.argv[1:] )

This way I can similate everything because I can pass main whatever list of
arguments that I want.

JustinHJ wrote:

> say you have a script in a file called test.py just type
>
> import test
>
> (you don't need the .py)
>
> As for doing stuff in the script it will execute any commands it encounters.
> It's neat to have all your stuff in functions and then have commands at the
> bottom to call the functions as needed. This is like a simulated main() from
> C.
>
> if __name__ == '__main__': # only run if main program
>  DoStuff( )
>
> Rolander, Dan <Dan.Rolander at marriott.com> wrote in message
> news:mailman.979855413.16209.python-list at python.org...
> > What is the best way to run a python script from within the interpreter?
> > What command should I use?
> >
> > Thanks,
> > Dan
> >




More information about the Python-list mailing list