tags:

views:

56

answers:

1

How can I execute a large number of scripts with IronPython and avoid the startup cost of ipy.exe? By large I mean over 100. Each script is a simple acceptance test for a service application and will run very quickly.

The simplest approach I can think of is a cmd file that loops through the *.py files calling:

ipy <filename1>.py
ipy <filename2>.py
...

However each script would then incur the overhead of starting ipy.exe. Some research on http://python.org turned up the exec function. A master python script that loops through each of the test script files and calls exec with the file contents looks like a viable alternative - is this a reasonable approach?

Edit: this was far simpler than I realized - see 2 lines below. Python is awesome!

for filename in list_of_files:
    exec(open(filename).read())
+1  A: 

Try execfile.

Nitin Bhide
Yes that does what I asked. However it will be deprecated in Python 3, and the suggested replacement is to use exec. But you've answered my question, so thank you!
James Holland