Share via


Learning IronPython #7: Running Script Files

To build upon my last post, you can run a script file by calling the execfile function and pass in the path and name of the script file. For example, you could create a file named BuildSearchPath.py in the c:\IronPython\MyModules folder with the following contents:

import sys
sys.path.append(r"c:\IronPython\MyModules")

You could then create a file named RunHelloGoodbye.py in the c:\IronPython\MyModules folder with the following contents:

import HelloGoodbye
HelloGoodbye.HelloWorld.HelloWorld()
HelloGoodbye.GoodbyeConsole.SeeYouLater()
HelloGoodbye.TheEnd()

Then you could type the following in the console:

>>> execfile(r"c:\IronPython\MyModules\BuildSearchPath.py")
>>> execfile(r"c:\IronPython\MyModules\HelloGoodbye.py")
>>> execfile(r"c:\IronPython\MyModules\RunHelloGoodbye.py")

And the console would display the following:

Hello, World!
Goodbye!
That's all, folks!

-- Paul

------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.