Python window

Using the Python window, you can access and execute geoprocessing and Python tasks and increase productivity by placing Python functionality in ArcGIS Pro. The Python functionality you run from this window can range from a single line to complex, multiline blocks of code.

The Python window also serves as a gateway to Python for those new to scripting, providing an intuitive interface in which to learn Python in ArcGIS Pro. In the Python window, various tool and method usage and syntax can be viewed and explored, and snippets of Python code can be entered or loaded into the window to test scripting ideas outside a stand-alone script.

The following key features 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 many 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.
  • Autocomplete functionality makes filling in geoprocessing tool parameters faster than using tool dialog boxes.

To open the Python window, on the Analysis tab, in the Geoprocessing group, click the drop-down menu under the Python button 新しいノートブック and click the Python window button Python ウィンドウを表示.

When initially opened, the Python window includes Python prompt and transcript sections. The prompt is at the bottom of the window, where code is written and entered. The transcript is above the prompt and provides a record of previously entered Python code. It is initially blank.

Python window prompt and transcript

When you press Enter after entering Python code at the Python prompt, the code is executed and moved to the transcript section. Any printed messages or errors will also appear in the transcript section. The Python prompt enlarges to fit the code entered and resizes to its default size after code is executed.

ヒント:

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

Access help

In Python, tools, functions, and classes all store helpful information. When using a geoprocessing tool, help information can be accessed by positioning the pointer within the round brackets following the name; the window will provide the syntax and the help for the current parameter. In addition, the help topic for any geoprocessing tool can be accessed by clicking the help button 情報.

Access help in the Python window

Save and load Python code

You can 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. On the Save As dialog box, provide a path and file name. This saves the current contents of the transcript, including the Python code, and messages and returned values are retained as code comments.

To load existing code from a Python file into the Python window, click in the Python prompt section, click Load Code, modify the code if necessary, and execute.


このトピックの内容
  1. Access help
  2. Save and load Python code