Bad file descriptor error when Updating attributes

2204
4
Jump to solution
07-08-2013 07:52 AM
ionarawilson1
Occasional Contributor III
The user digitizes a polygon and with the record selected it adds attributes to the record with a toolbox. The script works well without the 5th parameter (PlanEQIP) but I get a strange error message when I have this parameter. Does anybody know what the problem would be? Would it be because the field is short integer but the parameter data type is set to long?

Thanks!

Here is part of the code:
################################################## # #Script:  Attribute Table for reporting (Stewardship) #  ##################################################  #Import modules import os, sys, arcpy, traceback, arcgisscripting  #Set Map Document mxd = arcpy.mapping.MapDocument("Current")  #Set Overwrite Option arcpy.env.overwriteOutput = True   df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]  gp = arcgisscripting.create(10.1) #del row #del rows try: #Sets parameters (attributes)     Status = gp.GetParameterAsText(0)     Office =  gp.GetParameterAsText(1)     Forester = gp.GetParameterAsText(2)     DateStart = gp.GetParameterAsText(3)     PlanEQIP = gp.GetParameter(4)      StatusDomain = {'Completed': 'C', 'Pending': 'P'}     StatusCode = StatusDomain[Status]      officeDomain = {'Alpine': 'AL', 'Austin': 'AU', 'Carthage': 'CA', 'Corpus Christi': 'CC', 'Conroe': 'CO', 'Crockett': 'CR',                       'Crockett':'CR', 'College Station': 'CS', 'Canyon': 'CY', 'Dallas': 'DA', 'El Paso': 'EP', 'Fort Worth': 'FW',                       'Gilmer': 'GI', 'Granbury': 'GR', 'Hamilton': 'HA', 'Henderson': 'HE'}     officeCode= officeDomain[Office]     foresterDomain = {'Brittany Compton': 'bcompton', 'Brian Pope': 'bpope', 'Buster Robinson': 'brobinson',                         'Clay Bales': 'cbales', 'Daniel Duncum': 'dduncum', 'Daniel Lewis': 'dlewis'}     foresterCode = foresterDomain[Forester]   #Create Update Cursor     #Create Update Cursor    #This pre with arcpy.da prevents data locks. Another way of doing is (but it does not prevent data locks)  ##    rows = arcpy.UpdateCursor("Stewardship") ##    for row in rows: ##        row.Office = officeCode ##        row.Forester = foresterCode ##        rows.updateRow(row)       with arcpy.da.UpdateCursor("Stewardship", ("Status", "Office", "Forester", "DateStart", "PlanEQIP")) as rows:         # row comes back as a tuple in the order specified here, so Office is row[0], Forester is row[1]         for row in rows:             row[0] = StatusCode             row[1] = officeCode             row[2] = foresterCode             row[3] = DateStart             row[4] = PlanEQIP             rows.updateRow(row) 


And here is the error

Executing: Stewardship32 Completed Carthage "Brian Pope" "7/8/2013 10:40:49 AM" 17 Start Time: Mon Jul 08 10:40:54 2013 Running script Stewardship32... updateParameters Execution Error: Runtime error  Traceback (most recent call last):   File "D:\ArcGISData\SARS\Python_10April2013\SARS.tbx#Stewardship32.UpdateParameters.py", line 3, in <module>   File "D:\ArcGISData\SARS\Python_10April2013\SARS.tbx#Stewardship32.UpdateParameters.py", line 10, in __init__ IOError: [Errno 9] Bad file descriptor  Failed to execute (Stewardship32). Failed at Mon Jul 08 10:40:54 2013 (Elapsed Time: 0.00 seconds)
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ionarawilson1
Occasional Contributor III
According to this article the problem occurs due to print statements

http://support.esri.com/es/knowledgebase/techarticles/detail/35380

I had a print statement in one of the tool validation methods. I deleted the print statement and that fixed the issue.

View solution in original post

4 Replies
ionarawilson1
Occasional Contributor III
According to this article the problem occurs due to print statements

http://support.esri.com/es/knowledgebase/techarticles/detail/35380

I had a print statement in one of the tool validation methods. I deleted the print statement and that fixed the issue.
HillaryBjorstrom
Occasional Contributor

Thank you! This is worked for me. 

0 Kudos
StacyRendall1
Occasional Contributor III
Instead of print you should use arcpy.AddMessage(). This allows things to be printed to the screen whether you are running from the command prompt or as a script tool.
0 Kudos
ionarawilson1
Occasional Contributor III
Great! I need that ! Thank you Stacy!!!
0 Kudos