Using the Python window interactive console, you can run Python code directly from ArcGIS Pro through a Python interpreter, without requiring a script file. The Python code you run from this window can range from a single line to complex, multiline blocks of code.
The Python window is integrated with ArcGIS Pro so that geoprocessing tools can be conveniently run and reviewed in-app for increased productivity. Code snippets can be entered or loaded into the Python window to quickly test scripting ideas outside a stand-alone script. The Python window also serves as a gateway to Python for those new to scripting, providing an interface in which to learn Python syntax and explore Python functionality and geoprocessing tools.
The Python window contains the following features for running geoprocessing tools and experimenting with Python:
- 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 or multiline blocks of code can be entered and run.
- Tools or functions that have already been entered and run can be recalled, edited, and rerun.
- Python code can be loaded from existing Python files or saved to reload later or used in a different environment.
- Intelligent code completion, parameter info, quick help, and member list 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 .
When initially opened, the Python window includes 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.
When you press Enter after entering Python code at the Python prompt, the code runs and is 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.
When code runs in the Python window, a gray bar appears above the prompt with a cancel button to stop processing. If the cancel button is clicked, the code is interrupted with a KeyboardInterrupt exception.
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, you can access the help topic for any geoprocessing tool by clicking the help button .
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, and click Load Code.