Select to view content in your preferred language

<type 'exceptions.TypeError'>: 'function' object is unsubscriptable

556
2
07-06-2011 12:01 PM
LornaJewell
New Contributor
So, this is my code:

import arcpy
from arcpy import env
import os
#
env.workspace = arcpy.GetParameterAsText[0] #r"D:\Lorna\Project\Working\Outputs\LooseClip"
outLocation = arcpy.GetParameterAsText[1] #r"D:\Lorna\Project\Working\Outputs\ClippedFeaturesGDB.gdb"
# Use the ListFeatureClasses function to return a list of
# all shapefiles in workspace.
#
fcList = arcpy.ListFeatureClasses()
                              
#shapefiles are named <feature>Clip_<PAid>.shp
#this loop takes each fc, calculates a field which is populated by the PAid out of its file name
#and then appends the shapefile to the appropriate feature class.
for fc in fcList:
    myPA = fc[fc.find("_")+1:fc.find(".")]
    arcpy.CalculateField_management(env.workspace + os.sep + fc, "PAid", "\""+myPA+"\"", "VB", "")
   
    myFeature = fc[:fc.find("Clip")]        
    arcpy.Append_management(fc, outLocation + os.sep + "Clip"+ myFeature)
    print myFeature 

The user has to input each parameter as a string. It basically takes the features from a folder, puts an id into a field and appends them together (see comments). This works perfectly on its own, run from pythonwin, but fails miserably when I try to run it from model builder.

<type 'exceptions.TypeError'>: 'function' object is unsubscriptable

is the error I get.

Does anyone know what the problem is? I'm new to this so be nice!

Thanks for your help,

Lorna
Tags (2)
0 Kudos
2 Replies
StacyRendall1
Frequent Contributor
Hey,

Running from within Arc (modelbuilder or as a script tool) does seem to be kind of unstable at times (i.e.: http://forums.arcgis.com/threads/34444-InsertCursor-incredibly-slow-within-Arc).

First thing you could try is removing your calls to OS, and not importing it - especially as you are just using it to get the system separator - replacing the os.sep with '/' or '\\' should work just fine.

The next thing you could try is unchecking the "Run Python script in process" box when you are importing the script into Arc, but this often causes other problems...

Let me know how you get on!
0 Kudos
StacyRendall1
Frequent Contributor
Oh, your problem is actually the square brackets in GetParameterAsText:
env.workspace = arcpy.GetParameterAsText[0] #r"D:\Lorna\Project\Working\Outputs\LooseClip" 
outLocation = arcpy.GetParameterAsText[1] #r"D:\Lorna\Project\Working\Outputs\ClippedFeaturesGDB.gdb" 


They should be round brackets:
env.workspace = arcpy.GetParameterAsText(0) #r"D:\Lorna\Project\Working\Outputs\LooseClip" 
outLocation = arcpy.GetParameterAsText(1) #r"D:\Lorna\Project\Working\Outputs\ClippedFeaturesGDB.gdb" 


Square brackets are used for subscripts (indexes to lists, etc.), which is what your error was actually saying...
0 Kudos