15.02.2017 Views

Learning ArcGIS Pro

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Some Python basics<br />

Since this is your first introduction to Python, it is a good time to introduce some<br />

fundamentals and best practices. These will serve you well as you begin to write your own<br />

scripts.<br />

Commenting and documenting your scripts<br />

When you begin creating a Python script, it is considered a best practice to include<br />

documentation within the code that will help other developers understand what is<br />

happening within the code and the purpose of specific parts of the script. This can also<br />

prove helpful to yourself if you have to come back to a script you wrote some time ago<br />

and need to make changes.<br />

This code documentation is traditionally accomplished using commenting. Think of<br />

commenting code as a form of metadata stored within the code itself. It provides users and<br />

other programmers with the who, what, where, when, and whys they may need to<br />

successfully use, integrate, or edit a script you create. Different programming languages<br />

use different methods to comment code. Python uses the pound sign (#) to identify<br />

comment lines within its code as illustrated next:<br />

Anytime Python encounters a line that starts with a #, it ignores that line and moves to the<br />

next. It will keep ignoring lines until it encounters one that does not have a # at the<br />

beginning.<br />

It is also possible to use triple double quotations (""") to indicate a multiple line comment.<br />

Any text between the opening and closing triple quotes will be ignored.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!