Don Katnik Maine Department of Inland Fisheries & Widllife Organization of Fish & Wildlife Information Managers 2013 Conference

adventurescoldSoftware and s/w Development

Nov 7, 2013 (3 years and 9 months ago)

103 views

Don Katnik

Maine Department of Inland Fisheries & Widllife

Organization of Fish & Wildlife Information Managers 2013 Conference

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Why Program?

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife


Offical website: python.org


Released in 1991


Attempt to correct "what's wrong" with other languages


Named
after "Monty
Python"


General purpose


Interpreted


Object
-
oriented

What is Python?

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife


Free!


"Scripts" are just text files


Variety of free, enhanced code editors


Combines "remarkable power with very



clear syntax"


Minimalist language (dynamic declaration)


Can do same basic things as other languages


Portable across all major hardware/software platforms


"Glue" language for connecting different applications


Automate with Windows Task Manager

Why Python
?

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife


Text, numeric, array variables


Conditional blocks:


IF, THEN/ELSE


WHILE looping


FOR EACH (list) loops


Modular: Subs & Functions


Read/Write files


System Commands


Format text/numbers


User forms (primitive)

Usual Stuff

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife


Python Power!


Sequence of objects


Numbers, text, anything!


Even other lists (= array)


Lots of functions:


Sorting


Iterating


"in" (or "not in")


Fast!

Python Lists

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Dictionaries

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Tables in Dictionaries

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

TEMP Folder Problem

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

TempCleaner.py

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Flatfile

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Wildlife Obs Example

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Flatfile Workflow


Set path/source variables


Create empty shapefile (delete existing features)


Load relational DB tables into Python dictionaries


Create empty dictionary to store output


Loop through observations to populate output dictionary


Write output dictionary to empty shapefile

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Excel Spreadsheets

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Object Models


COM = Component Object Model


Language
-
netural way to manipulate objects


Object = an application, file/document, and the parts
that make up that document like worksheets, rows,
columns, cells, paragraphs, words, characters


Objects can have properties (characteristics) and
methods (things that can do) that can be manipulated by
code


Object Model = hierarchical diagram of the objects that
make up an application


http://msdn.microsoft.com/en
-
us/library/bb726436(v=office.12).aspx

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Word

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Text to PDF

Don Katnik

Maine Department of Inland Fisheries & Widllife

Organization of Fish & Wildlife Information Managers 2013 Conference

Don, Bronx, Misty & Jedzia

Acadia National Park, 2006

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife


Blocks of "reusable" code that can be called from within
the same script or from another script


Like a lookup table


Common in many programming languages


Functions are subroutines that return something


Can require any number of optional parameters


Functions "Return" a value

Subs & Functions

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Call PrintSomeText()


Def PrintSomeText():


print "Glad I came to OFWIM 2013!"

Sub Example

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Call PrintSomeText("BURN HER!!!!!!!!!!!!!!!!!!!!!")


Def PrintSomeText(txt):


print txt

Sub Example II

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Answer = Ask("What is your favorite color?")

More code here to determine if the answer was correct


Def Ask(Q):


if Q == "What is your name?":



A = "Sire Lancelot"


elif Q == "What is your quest?":



A = "To seek the Holy Grail"


elif Q == "What is your favorite color?":



A = "Blue"


return A

Function Example

Applications of Python Programming to Information Management


Don Katnik, Maine
Department
of Inland Fisheries &
Wildlife

Modules