Practical - introducing Python as a programming language

8 minutes
Share the link to this page


Hello, welcome to this tutorial about using Python in ArcGIS Pro. Please note that there is no difference between using Python in RGS Pro, and using it in ArcGIS basic, you can use the same functions. In the first video, I will show you how to make a Hello World application in Python. First, you need to download Python from their official website. Press on downloads and choose the latest Python version that you see displayed. The latest version at the moment of this recording is 3.6 or 2.7 point 13 for Python to lower on the page, you can find previous versions.

Once it has finished downloading, you need to press on the installer. You should see a pop up like this Here, take the option to the left of add Python 3.6 to pack then press on install now, you do not need to worry about any customization. When installation finishes click on disable path length limit. This will change the machine configuration to disable the 250 characters limitation. This will open a pop up asking you to allow this change. Press yes once installation is completed, you can search for idle in Windows, it will open a new window.

Python is an interpreted language. instructions are executed directly without compiling into machine language. It reads and executes functions interactively. We do not need to compile the program for debugging the code. This shell is interactive. We can debug the code directly here, I will write two plus two, then hit enter.

You can see the result in blue color. I recommend not to use this shell to write Python script. The shell does not save the file when you close it. We can use the shell to write simple mathematic expressions. Python follows the use of order in calculation of expressions. The standard order is first exponent, and roots, then multiplications divisions, finally, addition and subtraction for example, two to the power of five is written like this, times four divided by three minus two plus four, the result is 44.66.

On the other hand, if you want to use the previous result, you have to type underscore. This sign holds the value of the last executed statement in the interactive interpreter session. In the next example, I will write hello and press enter. In this case, the interactive shell it returns an error detailed in red. This is because the word hello is not a proper Python comment. However, if you use quotation marks, singles or doubles, it will appear an echo Have this word since you typed a string.

To make the Hello World program we need to open a new file. This is similar to a text file that you edit directly. This also means that you can use any text editor. However, if you want more tools and features, you need to install an interactive development environment known as IDE. This is helpful for editing, debugging, and invitation of code. There are many free and good options, such as pi Dev, pi charm, vim.

In this tutorial, we will work on the Python IDL quickly click on file then new file This will open a new window. This window will be our work area. The environment helps you develop code. For example, if I type a simple command, such as print, the word will change its color. This color represents the fact that print is a keyword in the Python language. This identifier is used as a reserved word.

Now open the parenthesis and quotation mark and type in hello world. Then close the quotation marks and the parenthesis. Once you have done this, click on file and save the project. Next, select the file path where you want to save the project and give the file a name. I will name it test dot p Why, make sure to type the extension file dot p y, since this will allow Python to open the file, when you double click it and execute the code. If you want to run the program, go to the run menu and press on run module.

Also, pressing f5 on your keyboard will run the code. Once you run the code, the result will appear in the Python shell. The Python source file is encoded in UTF eight by default. In this encoding, the characters of most languages in the world are written for string literals. identifiers and comments. The standard library only uses As CI characters or identifiers, this is a convention that any portable code should follow.

To display all these characters properly, your editor must recognize that the file is UT F and must use the same font for all characters in the file. If you want to declare a different encoding, a special comment line needs to be written at the beginning of the code file. For example, we declare windows 1252 by writing hashtag, dash, asterisk, dash coding, colon, CP dash 1252 dash, asterisk, dash, dash, asterisk dash to end The interactive session. You can either use exit or press the close button. If you choose the first option, Python will warn you that the program is still running and will ask you if you want to kill it. If you select Yes, the shell will close.

This is all for this video. In the next video, I will show you how to work with data types and structures.

Sign Up


Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.