execfile - saving me time

I'm continuing to test python scripts in version 10 with arcpy . When a long script encounters an error, I have been re-running it from the beginning. I came across the execfile command (knowing there must be a way to restart the script) and it has been very useful for me in picking up where I left off. I can look at the spot where things stop, and run this command in the Python Shell and I'm back in business.

The syntax is simply this … execfile(“path_and_filename.py”)

Arguments

To add arguments just do this

import sys
sys.argv = ["arg1", "arg2", "arg3"]
execfile("sameasalways.py")

exec too

On a related note, I figured out today how to execute a string as a command. I had the need to construct a series of commands using variables and was quickly able to do so after finding this forum post. It also covers the use of “eval” to get the value of an expression within a string.