Select to view content in your preferred language

Python Geoprocessing syntax from ArcGIS Pro 2.x to 3.x

421
1
Jump to solution
09-20-2023 06:13 PM
MarkChilcott
Occasional Contributor III

As we migrate from ArcGIS Pro 2.x to ArcGIS Pro 3.x, we a looking at Python Code.
I note in Pro 2.x the syntax in the documentation code samples for say Clip Analysis in the code samples is
                arcpy.Clip_analysis

Yet in pro 3.x it has switched to
                arcpy.analysis.Clip
 
Can anyone advise when this changed?

Do both work in Pro 3.x?

With the new syntax, I note my PyCharm code intelligence is now stuffed as well.  I think this is because the code document has not been changed.  ie this is in the analysis.py file in ArcPy

# Extract toolset

@gptooldoc('Clip_analysis', None)

def Clip(in_features=None, clip_features=None, out_feature_class=None, cluster_tolerance=None):

    """Clip_analysis(in_features, clip_features, out_feature_class, {cluster_tolerance})

Cheers,

Mark

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

arcpy.analysis.Clip is the native Python function call, i.e. Clip is a function in the module analysis from the site package arcpy, it can be found in the file "Path://to/ArcGIS/ArcPy/arcpy/analysis.py"

arcpy.Clip_analysis is the syntax you can use after you import a toolbox using ImportToolbox, which arcpy does automatically for the system tools.

 

Both work in ArcMap and ArcGIS Pro.


Have a great day!
Johannes

View solution in original post

1 Reply
JohannesLindner
MVP Frequent Contributor

arcpy.analysis.Clip is the native Python function call, i.e. Clip is a function in the module analysis from the site package arcpy, it can be found in the file "Path://to/ArcGIS/ArcPy/arcpy/analysis.py"

arcpy.Clip_analysis is the syntax you can use after you import a toolbox using ImportToolbox, which arcpy does automatically for the system tools.

 

Both work in ArcMap and ArcGIS Pro.


Have a great day!
Johannes