How to run script from interpreter?

Dan Rolander dan.rolander at marriott.com
Fri Jan 19 04:50:11 EST 2001


This doesn't work for me. I know how to import and how to use the if
__name__ trick, but how can I execute a script from the interactive Python
interpreter? That is, can I load a script and have it run from inside the
interpreter? (I'm sure this is easy I'm just not seeing it.)

Dan

----- Original Message -----
From: "JustinHJ" <justinhj at hotmail.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, January 18, 2001 7:37 PM
Subject: Re: How to run script from interpreter?


> 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
> >
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list