Select to view content in your preferred language

Python error question

9623
34
01-22-2015 04:33 PM
DEAF_PROBERT_68
Honored 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
DEAF_PROBERT_68
Honored Contributor

I put that damn r into what you suggest and it worked ...

Is the "r" stand for reclusive , correct ?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Glad it worked. The r is for "Raw String Notation":

https://docs.python.org/3.3/library/re.html#raw-string-notation  (sorry 3.3 docs)https://docs.python.org/3.3/library/re.html#raw-string-notation

If you copy and paste a path in python code it will probably be invalid since you have to use double backward slashed, forwards slashes or the r in front of the string holding the path. Normally the last option is the easiest,

0 Kudos
DEAF_PROBERT_68
Honored Contributor

Are you saying that when I copy and paste the code into python window in ArcMap  does it give you an errors ?

So that means do I have to re-type them ?

0 Kudos
DEAF_PROBERT_68
Honored Contributor

Earlier I mention that it worked.. That was all about the file geodatabase. Now I have one shapefile in the same mxd that did not  replace to the new workspace.

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

>>> path = "E:\ned10DEM\Contours"

>>> mxd.replaceWorkspaces(r"\E:\FY2011_projects\10mNED\Contours","SHAPEFILE_WORKSPACE", path + r"\","SHAPEFILE_WORKSPACE")

I still got an error here : Parsing error SyntaxError: invalid syntax (line 1)

0 Kudos
XanderBakker
Esri Esteemed Contributor

I think it should be:

mxd = arcpy.mapping.MapDocument("CURRENT")
path = r"E:\ned10DEM\Contours"
mxd.replaceWorkspaces(r"E:\FY2011_projects\10mNED\Contours","SHAPEFILE_WORKSPACE", path,"SHAPEFILE_WORKSPACE")

each time you specify a path (as string) place the r in front of it.

0 Kudos
DEAF_PROBERT_68
Honored Contributor

What are you using to run this code ? PyScripter ?  BTW Thanks.

0 Kudos
XanderBakker
Esri Esteemed Contributor

I didn't run the code, but when I do I use PyScripter.

0 Kudos
DEAF_PROBERT_68
Honored Contributor

Using Python Windows within ArcMap.  I think I need to try and use PyScripter. I have to ask my IT Specialist for permission to use it on my computer.

Thanks.

0 Kudos
XanderBakker
Esri Esteemed Contributor

If I'm correct you can download the ZIP which does not need an installation...

Downloads - pyscripter - An open-source Python Integrated Development Environment (IDE) - Google Pro...

zip file for registry free installation

BlakeTerhune
MVP Frequent Contributor

It installs with a different shortcut for each Python version. Do we need to make sure we are running the PyScripter for Python 2.7 so it's "compatible" with ArcGIS? I seem to remember something about this being the case.

0 Kudos