Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm having a problem with the following script. When listing parameters that are optional I've used the "" before, so I can't figure out why this isn't working.

import arcpy
import os

arcpy.env.overwriteOutput = True

path = "C:/Data_new/Temp/Default.gdb"
name = "point_shapefile.shp"
type = "POINT"

m = "DISABLED"
z = "DISABLED"
prjFile = "C:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems" + \
      "/State Plane/NAD 1983 (US Feet)/NAD 1983 StatePlane North Carolina FIPS 3200 (US Feet).prj"
reference = arcpy.SpatialReference(prjFile)

arcpy.CreateFeatureclass_management(path, name, type, "", m, z, reference)
share|improve this question
    
What is the exact error you are getting? "Name contains invalid characters"? –  Chad Cooper Jan 25 '13 at 16:01

2 Answers 2

Lose the .shp in name, since your workspace is a geodatabase -- no file extension required.

Alternatively, change path to a regular folder instead of a geodatabase.

share|improve this answer
    
Thanks...dropping the .shp did the trick. I could have sworn that I've used it before in other scripts, but now I know. –  KFP Jan 25 '13 at 16:20
    
Great! Please don't forget to mark this as the accepted answer :) –  nmpeterson Jan 26 '13 at 6:07
    
Another little tip especially on Windows is to prepend an 'r' to the front of path strings. This tells Python to treat it as a raw string and it automatically escapes the slashes. This way you avoid accidentally passing things like newline (/n) and many other special characters. So your 4th line would read: path = r"C:/Data_new/Temp/Default.gdb". Obviously, this wasn't your problem here but it's a common 'gotcha' and so a good habit to add that little 'r' (and a heck of a lot quicker/thorough than manually escaping the slashes!). –  MappaGnosis Jan 26 '13 at 9:19

While your issue really turned out to be a code writing issue, I'll answer the question that was asked.

Rather than simply using double quotes for your optional parameters, you should really consider using a quoted pound sign ("#"), as noted in the help article Executing tools in the Python window under the "Required versus optional parameters" subsection.

Optional parameters have default values. If you enter a quoted # (pound sign), "" (two double quotes), '' (two single quotes), or a Python None for an optional parameter, the default parameter value will be used. For keywords, the default value is the first keyword in the list. See the help for an individual tool for its default parameter values.

Using a quoted pound sign will make it much more obvious to future code readers (and likely writer) that it is an intentionally set default parameter, rather than a potentially forgot about parameter that never got filled in.

share|improve this answer
    
What makes code even more clear is to specify parameters by name, e.g. spatial_reference=reference instead of just reference -- the added bonus being that parameters can be listed in any order and optional parameters using default values can be omitted completely. –  nmpeterson Jan 25 '13 at 20:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.