Hi. I'm a GIS Instructor at a community college, trying to incorporate more Python into my curriculum. I've assigned my students the ESRI course, "Python Scripting for Map Automation" for desktop, but one student is having repeated error messages in the second course exercise - see snip below:
I'm wondering if there is an issue related to where the Python program 'lives' on the student's computer, and that's why changing the workspace gives errors? Thanks if anyone has ideas on what I can advise the student to try.
missing a \
path = r"c:\folder\sub" path + r"\some.gdb" # -- add \ 'c:\\folder\\sub\\some.gdb'
Try remove the "r" from r"\city of westervill.mdb" and r"\westerville.gdb". Are both the mdb and gdb in the same folder "c:\esritraining\mapscripting? Include arcpy.env.workspace
I have always done something like this.
mxd = arcpy.mapping.MapDocument("CURRENT")#mxd = arcpy.mapping.MapDocument(mxd) mxd.findAndReplaceWorkspacePaths(r"Database Connections\Connection to OLD_sqlexpress.sde", r"Database Connections\Connection to New_sqlexpress.sde") #Database Servers\***.gds for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == "CITY_LIMITS": lyr.replaceDataSource(r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.7\ArcCatalog\***.gds", "SDE_WORKSPACE", "***.DBO.City_Limits","") print "Successfully updated CITY_lIMITS data sources"
Thanks for the ideas, Dan and 2Quiker. I should've posted a snip of my version, what it should look like:
I had my student add the 'r' thinking that would help with the path, but it didn't work either way.
the student was missing a "\" not just the r thing
Hi. So, yes the .gdb and the .mdb in this ESRI training module both exist in "C:\EsriTraining\MapScripting" folder...The "r" and extra "\" were not needed per the training module directions (I only has student add that later in effort to get code to work) - if look at my (not student) script in snip above, the code is the way the instructions were written in module (but didn't work for student). The student copied/pasted the code from the Esri training directions originally, so I still wonder if the error codes have something to do with a different version of Python being referred to....this student (like I do too) has more than one version of Python installed, since Pro uses different version than ArcMap. So maybe the question is how to make sure ArcMap is pulling from the correct one? Thanks.