ArcGIS Pro

The Python window

In this topic

The Python window is convenient for efficiently accessing and executing geoprocessing and Python tasks and increasing productivity by placing Python functionality within ArcGIS Pro. The Python functionality run from this window can range from a single line to complex, multiple-line blocks of code.

The Python window also acts as a gateway to Python for those new to scripting, providing an intuitive interface that makes learning Python in ArcGIS Pro as easy as possible. In the Python window, various tool and method usage and syntax can be viewed and experimented with, and snippets of Python code can be entered or loaded into the window to test scripting ideas outside a stand-alone script.

There are several key features that make the Python window a valuable resource for running and experimenting with Python commands and syntax:

The Python window interacts with ArcGIS Pro, working with layers and other contents of your map, using the application's environment settings and adding the output of geoprocessing tools to your map.

All Python functionality, including ArcPy, core Python functionality, including the Python standard libraries, and several additional third-party libraries are exposed through the Python window.

Single commands or multiline blocks of code can be entered and executed.

Tools or functions that have already been entered and executed can be recalled, edited, and reexecuted.

Python code can be loaded from existing Python files or saved to reload later or used in a different environment.

When initially opened, the Python window includes Python prompt and transcript sections. The prompt is where code is written and entered and is initially reduced to its smallest size. The transcript provides a record of previously entered Python code and is initially blank.

Python code is entered at the Python prompt. After pressing Enter following the code, the code is executed and moved to the transcript section. Any printed messages or errors will also show in the transcript section. The Python prompt enlarges to fit code entered and resizes to its default sizing after code is executed.

Note:

When working with multiple lines of code, use Ctrl+Up arrow and Ctrl+Down arrow to recall previously executed Python code. Otherwise use Up arrow or Down arrow to move from line to line.

Access help

In Python, tools, functions, and classes all store helpful information with them. This information can be accessed by using the Python built-in help function with any module, tool, function, class, or method as the first argument. In the illustration below, access the Python help for arcpy.ListFiles.

Saving and loading Python code

The Python window provides a useful environment to learn about and experiment with Python in ArcGIS Pro. In many cases, it may be useful to save work completed in the Python window to a file that can be used in later sessions or further refined in a Python integrated development environment (IDE). To save code from the Python window, click in the transcript section and click Save Transcript. In the Save As dialog box, provide a path and file name. This will save the current contents of the transcript, including the Python code, while messages and returned values will be retained as code comments.

The Python window is an interactive Python prompt that is useful for quick execution of Python functionality. However, code that has already been written to a Python file can also be loaded into the Python window by clicking in the Python prompt section and clicking Load Code, and then modified if needed and executed.