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

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…
主站蜘蛛池模板: 奎屯市| 安陆市| 德令哈市| 泰安市| 南投市| 银川市| 寿光市| 穆棱市| 饶阳县| 泰顺县| 云和县| 英吉沙县| 渭南市| 延边| 运城市| 晴隆县| 巴塘县| 当涂县| 湟源县| 高邮市| 东乡| 松潘县| 扬州市| 河北省| 全椒县| 台州市| 永登县| 汝南县| 随州市| 丰城市| 石家庄市| 贵定县| 卓尼县| 科技| 内乡县| 岳普湖县| 宾阳县| 汤原县| 潞城市| 黔西县| 和龙市|