Python error question

7087
34
01-22-2015 04:33 PM
PROBERT68
Frequent Contributor

I am a beginner and just starting to learn how to use Python I learned from Python Scripting for Map  Automation.

My question to you is that whenever I get an error I see the word Traceback or errors in highlight red in my python window. 

My question to you is do I need to have a pythonWin installed ? My computer at work does not have it but I use the python  Window inside ArcMap.

 

Are there site that can I read or learn about the Traceback error ? I am sure there are bunch of question that Traceback has in it.

 

So what does Traceback means and what does it do ?

 

Thanks

0 Kudos
34 Replies
XanderBakker
Esri Esteemed Contributor

It helps to "trace back" the line where the error occurred.

The documentation can be found here:

28.10. traceback — Print or retrieve a stack traceback — Python 2.7.9 documentation

And you should read this help topic: Error handling with Python

0 Kudos
DanPatterson_Retired
MVP Emeritus

the python docs are here why dont you install pythonwin and/or Pyscripter the Arc* ide is pretty useless

0 Kudos
FranciscoGirón_Gesteira
New Contributor

If you are just beginning there is no need to install anything. Every Python installation includes IDLE, a simple grafical interface with many basic funtionalities including debugging, colorizing, auto-indentation, etc. Not as good as Pyscripter, but is already installed. I personally don't like Pythonwin. Just a thing, if using an external IDE, remember putting an "import arcpy" line at the start of every script you write.

If you are able to install Pyscripter set up the options to read arcpy help and perform code completion with it. Just add arcpy to the special packages line under code completion in IDE options.

The Traceback shows you the line of your code where an error occurred, and which kind of error it is. It should be more than enough in the beginning, forget about try/exception and others until you are writing your own scripts.

0 Kudos
PROBERT68
Frequent Contributor

the only problem is that my computer is under Government and it must be approve before I can use them.  Does it have any issue ?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Both are harmless although they need to make registry additions for which you may not have permissions to do.  You will quickly find out if you can install either by yourself or need your Administer to do so.

0 Kudos
PROBERT68
Frequent Contributor

Right now I am at work and here is the error i am having ....

>>> mxd.replaceWorkspaces("","NONE","E:\State_mosaic\Elevations.gdb","FILEGDB_WORKSPACE")

Runtime error

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_

    return fn(*args, **kw)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\_mapping.py", line 915, in replaceWorkspaces

    return convertArcObjectToPythonObject(self._arc_object.replaceWorkspaces(*gp_fixargs((old_workspace_path, old_workspace_type, new_workspace_path, new_workspace_type, validate), True)))

ValueError: MapDocObject: Unexpected error

0 Kudos
XanderBakker
Esri Esteemed Contributor

How do you set you mxd variable?

0 Kudos
PROBERT68
Frequent Contributor

mxd = arcpy.mapping.MapDocument("CURRENT")

0 Kudos
XanderBakker
Esri Esteemed Contributor

That shouldn't be a problem if you run the code from the Python Window inside ArcMap.

What happens if you place an r before "E:\State_mosaic\Elevations.gdb":

mxd.replaceWorkspaces("","NONE",r"E:\State_mosaic\Elevations.gdb","FILEGDB_WORKSPACE",True)

0 Kudos