GIS5103 Module 2: Python Fundamentals
This week’s lab in GIS Programming focused on the fundamentals of Python. We worked with string variables, how to include comments in script in a way that wouldn’t impact the script outcome, how to iterate variables within loops to control script workflow, as well as created loops and conditional statements.
Part 1 of lab included being able to assign a variable as a
string, splitting that string into a list, and indexing to pluck
the last string list item as the output when ran. For this part, we assigned
our full name as the variable and indexed the script to print our last name.
Part 2 of lab consisted of looking at prewritten script for
a dice game and trying to determine the (2) errors that prevented the script
from running without error.
Part 3 of lab asked that we create a loop that will add (20)
random numbers between (0) and (10) to a list. We needed to utilize a while loop
that appended a randomly generated number for this and then use an if statement.
Part 4 of lab asked us to pick a random number from that
list generated in Part 3 that we wanted excluded. We used the count() method to see how many times the number pops
up within the list and made a print statement that indicated how many times the
number was taken out. Alternatively, if the number we chose to exclude was not
included in the list, we created a print statement that indicated so.
Because we wanted out chosen number to be gone, we used a while loop and
the remove() method to take it out and then printed the updated list
that excluded our chosen number.
![]() |
| Results in ArcGIS Notebook - see above text to see the colored coded results for each Step/Part of Lab 2 - GIS Programming |
![]() |
| Flowchart for Step/Part processes used in Lab 2 - GIS Programming |
A few note from Lecture:
Lecture
-
Arc
Macro Language (AML): early (~1980’s) ESRI product
-
Visual
Basic for Applications (VBA): 1999 in ESRI, earlier in Microsoft. Primary
scripting language for ESRI until 2010 when switched to Python.
-
Python
created/released in 1991 (Rossum)
-
AcrPy –
how Python collaborates w/ ArcGIS
-
Scripting
language: used to work w/ and automate processes using components. Interpreted
AS ran.
-
Programming
language: used to BUILD components that scripting language uses. Complied
BEFORE ran.
-
Syntax:
TYPE of programming language. Texts, numbers, symbols entered in interpreter interface.
-
Data type:
determines what type of value variable hold/operations that can be done.
-
Python
is OBJECT ORIENTED PROGRAMMING (OOP) language.
-
Boolean:
Subtype to plain integers
-
Python
uses DYNAMIC ASSIGNMENT to infer data types
-
An expression
is a value
-
A statement
assigns a value/tells computer to do something
-
Functions
carry out specific action.
-
Methods
closely coupled to an
object.
-
len is a
built in function = length
-
Parameter
is equal to argument
-
str() is
function used to cast objects to a string – may need to use when
concatenating strings
-
print
dir(math) can show math
functions available – module.function(s) to call function
-
Nested
function: input functions w/I input function
-
While loop: needs exit condition, sentry variable
-
For loop: based on a sequence, codes for end of
sequence. Used when want repeat specific amount of times.
-
split()
will split into list

.png)
Comments
Post a Comment