Pyton Window workspace path character limit?

811
1
Jump to solution
09-26-2012 12:17 PM
AustinStreetman
New Contributor III
Is there a limit to the number of characters in a workspace path when using the Pyton Window?

This example from a tutorial works fine:
>>> mxd.replaceWorkspaces("D:\Student\PythonDesktop10_0\Data\Austin_test.gdb",
"FILEGDB_WORKSPACE",
"D:\Student\PythonDesktop10_0\Data\Westerville.gdb",
"FILEGDB_WORKSPACE")

But this does not:
>>> mxd.replaceWorkspaces("D:\Student\PythonDesktop10_0\Data\Westerville.gdb",
"FILEGDB_WORKSPACE",
"W:\AEP\127142_Opossum_Creek_Smith_Mtn\PER\Environmental\GIS\Data\temp\Austin_test.gdb",
"FILEGDB_WORKSPACE")

Runtime error <type 'exceptions.ValueError'>: MapDocObject: Unexpected error
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Frequent Contributor
Is there a limit to the number of characters in a workspace path when using the Pyton Window?

This example from a tutorial works fine:
>>> mxd.replaceWorkspaces("D:\Student\PythonDesktop10_0\Data\Austin_test.gdb",
"FILEGDB_WORKSPACE",
"D:\Student\PythonDesktop10_0\Data\Westerville.gdb",
"FILEGDB_WORKSPACE")

But this does not:
>>> mxd.replaceWorkspaces("D:\Student\PythonDesktop10_0\Data\Westerville.gdb",
"FILEGDB_WORKSPACE",
"W:\AEP\127142_Opossum_Creek_Smith_Mtn\PER\Environmental\GIS\Data\temp\Austin_test.gdb",
"FILEGDB_WORKSPACE")

Runtime error <type 'exceptions.ValueError'>: MapDocObject: Unexpected error


If those were the example paths given they are setting you up for failure. You bombed here \temp
\t in a string is read as a tab. To avoid this issue use double \\, / or the easiest method in my opinion, the r tag before your string.

mxd.replaceWorkspaces(r"D:\Student\PythonDesktop10_0\Data\Westerville.gdb",  "FILEGDB_WORKSPACE",  r"W:\AEP\127142_Opossum_Creek_Smith_Mtn\PER\Environmental\GIS\Data\temp\Austin_test.gdb", "FILEGDB_WORKSPACE")


You can read more about string literals, what they do and how to avoid them here.
http://docs.python.org/reference/lexical_analysis.html#string-literals

View solution in original post

0 Kudos
1 Reply
MathewCoyle
Frequent Contributor
Is there a limit to the number of characters in a workspace path when using the Pyton Window?

This example from a tutorial works fine:
>>> mxd.replaceWorkspaces("D:\Student\PythonDesktop10_0\Data\Austin_test.gdb",
"FILEGDB_WORKSPACE",
"D:\Student\PythonDesktop10_0\Data\Westerville.gdb",
"FILEGDB_WORKSPACE")

But this does not:
>>> mxd.replaceWorkspaces("D:\Student\PythonDesktop10_0\Data\Westerville.gdb",
"FILEGDB_WORKSPACE",
"W:\AEP\127142_Opossum_Creek_Smith_Mtn\PER\Environmental\GIS\Data\temp\Austin_test.gdb",
"FILEGDB_WORKSPACE")

Runtime error <type 'exceptions.ValueError'>: MapDocObject: Unexpected error


If those were the example paths given they are setting you up for failure. You bombed here \temp
\t in a string is read as a tab. To avoid this issue use double \\, / or the easiest method in my opinion, the r tag before your string.

mxd.replaceWorkspaces(r"D:\Student\PythonDesktop10_0\Data\Westerville.gdb",  "FILEGDB_WORKSPACE",  r"W:\AEP\127142_Opossum_Creek_Smith_Mtn\PER\Environmental\GIS\Data\temp\Austin_test.gdb", "FILEGDB_WORKSPACE")


You can read more about string literals, what they do and how to avoid them here.
http://docs.python.org/reference/lexical_analysis.html#string-literals
0 Kudos