官术网_书友最值得收藏!

Using the ArcGIS Python window

In this recipe, you'll learn how to use the ArcGIS Python window. In Chapter 1, Fundamentals of the Python Language for ArcGIS, you learned how to use the IDLE development environment for Python, so this chapter will give you an alternative for writing your geoprocessing scripts. Either development environment can be used but it is common for people to start writing scripts with the ArcGIS Desktop Python window and then move on to IDLE when scripts become more complex. I should also mention that there are many other development environments that you may want to consider, including PythonWin, Wingware, Komodo, and others. The development environment you choose is really a matter of preference.

Getting ready

The new Python window is an embedded, interactive Python window in ArcGIS Desktop 10, that is ideal for testing small blocks of code, learning Python basics, building quick and easy workflows, and executing geoprocessing tools. However, as your scripts become more complex, you'll quickly find the need for a more robust development environment. By default, IDLE is installed with ArcGIS Desktop, so this is a logical next choice for many. For new programmers, though, the ArcGIS Python window is a great place to start!

The ArcGIS Python window has a number of capabilities in addition to being the location for writing your code. You can save the content of the window to a Python script file on a disk or load an existing Python script into the window. The window can be either pinned or floating. While floating, the window can be expanded or contracted as you wish. The window can also be pinned to various parts of the ArcGIS display. You can also format the font and text colors displayed in the window by right-clicking on the window and selecting Format.

How to do it…

The Python window can be opened by clicking on the Python window button on the main ArcGIS Desktop toolbar.

  1. Open c:\ArcpyBook\Ch2\Crime_Ch2.mxd with ArcMap.

    Note

    You don't have to specifically open Crime_Ch2.mxd. Any map document file can be used with the Python window.

  2. Click on the Python window button from the main ArcMap toolbar. The Python window will be displayed as shown in the following screenshot. This is a floating window, so you can resize as needed and also dock it at various places on the ArcMap interface:
    How to do it…

    The Python window is essentially a shell window that allows you to type in statements one line at a time, just after the line input characters >>>. On the right-hand side of the divider, you will find a help window.

  3. Load an existing script by right-clicking inside the Python window and selecting Load from the menu. Navigate to the c:\ArcpyBook\Ch2 directory and select ListFields.py to load a sample script.

    You can also format the font and text colors displayed in the window by right-clicking on the window and selecting Format. You will be provided with White and Black themes; you can select fonts and colors individually:

    How to do it…

Click on the Set Black Theme button to see an example. If you spend a lot of time writing code, you may find that darker themes are easier on your eyes:

How to do it…
主站蜘蛛池模板: 垦利县| 涪陵区| 大冶市| 呼图壁县| 大埔县| 波密县| 宜都市| 碌曲县| 石门县| 洛宁县| 增城市| 蒲江县| 玉溪市| 张家界市| 石城县| 娱乐| 宝兴县| 嘉黎县| 阜南县| 长宁区| 盈江县| 西乌| 南召县| 水富县| 龙泉市| 鱼台县| 尤溪县| 宣汉县| 久治县| 尚志市| 通山县| 炎陵县| 南阳市| 贡嘎县| 平谷区| 乐亭县| 屯留县| 安国市| 蒲江县| 丰镇市| 金堂县|