Using the new Python window in ArcGIS Pro

If you've been using the Python window in ArcGIS for Desktop, you'll already be pretty familiar with the Python window in ArcGIS Pro. However, there are some differences between the two and some improvements as well. In this recipe, you'll learn how to use the ArcGIS Pro Python window.

The Python window in ArcGIS Pro functions in much the same way as the window in ArcGIS for Desktop. It serves as an integrated tool used to execute Python code for geoprocessing operations. Using the Python Window, you can execute Python functionalities, including ArcPy, core Python functionalities, and third-party libraries. Python code that you write in the window can be saved or loaded from an existing script source. The inclusion of autocompletion functionality makes it easier to complete coding operations, including calling tools and passing parameters. In this recipe, you'll learn how to use the ArcGIS Pro Python window.

Follow these steps to learn how to use the ArcGIS Pro Python window:

  1. Open ArcGIS Pro and select a project or create a new project.
  2. Click on the ANALYSIS menu item in ArcGIS Pro and then the Python tool, as shown in the following screenshot:
    Using the new Python window in ArcGIS Pro
  3. This will display the Python window at the bottom of the ArcGIS Pro window, as seen in the following screenshot:
    Using the new Python window in ArcGIS Pro
  4. The Python window can be pinned, unpinned, and resized.
  5. There are two basic sections of the Python window in ArcGIS Pro: Transcript and Python prompt. Both are shown in the following screenshot. You will write code in the Python prompt section one line at a time. The transcript section provides a record of Python code that has already been executed.
    Using the new Python window in ArcGIS Pro
  6. After typing in a line of code, you press the Enter key on your keyboard and the code is executed and moved to the transcript section. Print messages are written to the transcript window as errors. Type the following line of code to import the ArcPy mapping module:
    import arcpy.mp as MAP
  7. The ArcGIS Pro Python window has a code completion functionality so that as you begin typing, various matching options will be presented that provide a current match to what you have typed. You can select one of the items from the presented list to complete the typing. You can see an illustration of this by typing arc in the Python prompt. The code completion functionality will present two options: arcgis and arcpy.
  8. You can access the built-in help system by using the help() method. Type help(arcpy.ListFeatureClasses()) in order to see an illustration of the help documentation that is provided:
    Using the new Python window in ArcGIS Pro
  9. You can save any Python code that you have written by right-clicking inside the transcript section and selecting Save Transcript. In addition to this, you can load an existing Python script into the window by right-clicking in the prompt section and selecting Load Code.

The ArcGIS Pro Python window can be used to write basic Python geoprocessing scripts, execute tools, access ArcPy and its associated modules, Python core modules and third-party modules, load and execute existing Python scripts, save Python scripts for later use, and obtain help for ArcPy classes and functions. However, there are coding differences between ArcGIS for Desktop and ArcGIS Pro.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset