r(以便正确解释)来使用字符串文本。

示例 1:Python 中路径的有效使用

import arcpy

arcpy.GetCount_management("c:/temp/streams.shp")
arcpy.GetCount_management("c:\\temp\\streams.shp")
arcpy.GetCount_management(r"c:\temp\streams.shp")

示例 2:Python 中路径的无效使用

\t 被 Python 解释为制表符。由于解释的路径与所期望的路径不同,GetCount 将失败。

import arcpy
arcpy.GetCount_management("c:\temp\streams.shp")

# ExecuteError: Failed to execute. Parameters are not valid.
# ERROR 000732: Input Rows: Dataset c:      em\streams.shp does not exist or is not supported
# Failed to execute (GetCount)
使用 Python 设置数据的路径提示:

同一地理数据库中的要素类和要素数据集可以具有相同的名称。在这种情况下,要素类和要素数据集将具有相同的 ArcCatalog 路径。大多数工具都需要处理其中的任一种。但是,对于要素类和要素数据集都能处理的工具(如复制工具),可能要指定数据类型以避免混淆。

相关文章: