[Tutor] Checking Syntax
alan.gauld at btinternet.com
Fri Jun 19 01:26:38 CEST 2009
"Kevin Pearson" <kevinfpearson at gmail.com> wrote
> run a check on the sytax (before I try running the program) it places a
> cursor like so:
> outFeatureClas|s = outWorkspace + "/" +
You should try running it, the error message may be more
helpful than the syntax checker...
However, it will also help make your code more readable
is you insert some blank lines to break it into logical groups
Also most of the comments are really bad stylistically since
they simply describe what the code is doing which is in most cases
self evident even to a beginner. Comments should describe *why*
the code is as it is, not what it is. I've removed the worst cases.
> #Import standard library modules
> import win32com.client, sys, os
> #Create the Geoprocessor object
> GP = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
> #argv is the name of the script
> GP.workspace = sys.argv
> clipFeatures = sys.argv
> outWorkspace = sys.argv
> clusterTolerance = sys.argv
> fcs = GP.ListFeatureClasses()
> #always reset a list so the first item is extracted
> #so you can be sure you get the first item in the list
> fc = fcs.Next()
> while fc:
> # returns unique name so no existing data is overwritten.
> outFeatureClass = outWorkspace + "/" + GP.ValidateTableName(fc,
Notice that this line is supposerd to be inside the body of a while loop.
That means it should be indented. Because it isn't the syntax checker
thinks there is a missing body to the loop. Your line is the first line
after Python detects the error so thats where the cursor stops.
> #Do not clip the clipFeatures, it may be in the same workspace.
> if str(fc) != str(os.path.split(clipFeatures)):
> GP.Clip(fc, clipFeatures, outFeatureClass,
> fc = fcs.Next()
I suspect all of these lines should be indented too...
> print GP.GetMessages(2)
Author of the Learn to Program web site
More information about the Tutor