[Tutor] Checking Syntax
Emile van Sebille
emile at fenx.com
Thu Jun 18 22:47:21 CEST 2009
On 6/18/2009 12:55 PM Kevin Pearson said...
> I am teaching myslef Python from a GIS tutorial
> I have typed everything exactly like it is in the tutorial and when I go
> to run a check on the sytax (before I try running the program) it places
> a cursor like so:
> outFeatureClas|s = outWorkspace + "/" +
> I have checked the tutorial and I can't see what is wrong. I can't get
> past this until it is corrected.
> I have attached the script.
> Any advice would be greatly appreciated.
> #Import standard library modules
> #imports system, operating system & Windows 32 modules
> #sys refers to Python system, os refers to acess to operating system
> import win32com.client, sys, os
> #Create the Geoprocessor object
> GP = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
> #Set the input workspace
> #argv = argument value
> #argv is the name of the script
> GP.workspace = sys.argv
> #Set the clip featureclass
> clipFeatures = sys.argv
> #Set the output workspace
> outWorkspace = sys.argv
> #Set the cluster tolerance
> clusterTolerance = sys.argv
> #try statement defines the beginning of a block of code that will be
> #handled by its associated exception handler, or except statement
> #try/except statements are used to handle unexpected errors
> #this defines that the program should do when an exception happens
> #Get a list of the featureclasses in the input folder
> fcs = GP.ListFeatureClasses()
> #Loop through the list of feature classes
> #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:
I don/t know if this is the only case, but certainly you'll need to
increase indentation level after any lines ending in a colon that
indicate the start of a block. This type of error can cause cryptic
messages to the thrown up that don't always point to the actual problem.
> #Validate the new feature class name for the output workspace.
> #ValidateTableName ensures output name is valid for output
> #workspace, it returns unique name so no existing data is overwritten.
> outFeatureClass = outWorkspace + "/" + GP.ValidateTableName(fc,
> #Clip each feature class in list with the clip feature class.
> #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()
> #except statement is required by the earlier try statement
> #if an error occurs during execution the code in the except
> #block will run
> print GP.GetMessages(2)
> Tutor maillist - Tutor at python.org
More information about the Tutor