Select to view content in your preferred language

Debug python script under arcmap

650
3
11-19-2012 03:29 AM
PhilippeSTEINMANN
Occasional Contributor
Hi,

When I run my Python script in ArcMap from my toolbox, I would start debugging ... how?

I use PythonWin and also Python Tools for VS2010;
I tried in VS2010 the command 'attach to process' but it does not work ...

How do you do?

thank you very much
Tags (2)
0 Kudos
3 Replies
PhilippeSTEINMANN
Occasional Contributor
0 Kudos
PhilippeSTEINMANN
Occasional Contributor
it's the same road in VS2010 .... in options in Projet
0 Kudos
MattSayler__Work_
Deactivated User
Not sure if this will help, but here is a function I found (I think in these forums somewhere, apologies to the original contributor). Isn't as nice as being able to step through, but (usually) gives the offending line's number in the results dialog.

### Geoprocessing script traceback error info ###
import os, sys, traceback
def trace():
 tb = sys.exc_info()[2]
 tbinfo = traceback.format_tb(tb)[0] # script name + line number
 line = tbinfo.split(", ")[1]
 
 # Construct the pathname to this script.  Get the pathname
 #  to the folder containing the script using sys.path[0].
 #  Modify line below and replace 'myscript.py' with the name of
 #  this script.
 
 filename = sys.path[0] + os.sep + "ScriptFileName.py" #<--- Insert filename
 
 # Get Python syntax error
 synerror = traceback.format_exc().splitlines()[-1]
 return line, filename, synerror
 
## Try-Except clause format:
# try:
# your code here
# except arcpy.ExecuteError:
 # for msg in range(0, arcpy.GetMessageCount()):
  # if arcpy.GetSeverity(msg) == 2:
   # arcpy.AddReturnMessage(msg)
# except:
 # line, filename, err = trace()
 # arcpy.AddError("Python error on " + line + " of " + filename)
 # arcpy.AddError(err)
 # print "Python error on " + line + " of " + filename
 # print err
0 Kudos