me, but we will find an answer – Expect tangents • NOT geared totally to ArcGIS • Let’s cover some important basics • Python for accomplishing other tasks • THINK – oddball and out of the ordinary applications will make you want more…
strings: path = r”C:\temp\chad\” • Slicing fruit[0] ‘b’ • Indexing: fruit[1:3] >> ‘an’ • Iteration/membership: for each in fruit ‘f’ in fruit • String formatting: ‘a %s parrot’ % ‘dead’ ‘a dead parrot’
cannot add, remove, find • Access by offset • Basically an unchangeable list (1,2,’three’,4,…) • So what’s the purpose? – FAST – great for iterating over constant set of values – SAFE – you can’t change it
– collection of distinct objects – NO DUPLICATES • Example – get rid of dups in a list L1=[2,2,3,4,5,5,3] L2=[] [L2.append(x) for x in L1 if x not in L2] >>> L2 [2, 3, 4, 5]
into memory – OK except for huge files data = open(file).read().splitlines() • Iterate over the lines for line in data: do something • CSV module reader = csv.reader(open('C:/file.csv','rb')) for line in reader: do something
C:\temp\python\simple-csv.csv • Read into memory (create reader, open file) • Print it out, slice it up, use indexes • Put contents into a dictionary (zip module) • Put dictionary items into a list (list.append(dictionary item) • Exercise-1.py and Exercise-1B_Write_Text_File.py
ftplib – log in, nav to directory, retrieve files • urllib/urllib2 – pass in the url you want, get it back • wget – GNU commandline tool – Can call with os.system()
content is a HUGE help, as is valid markup, which isn’t always there • BeautifulSoup 3rd party module – Built in methods and regex’s help out – Great for getting at tables of data
IP of your email server • Port blocking can be an issue import smtplib server = smtplib.SMTP(email_server_ip) msg = ‘All TPS reports need new cover sheets’ server.sendmail('[email protected]', '[email protected]', msg) server.quit() • There’s always Gmail too…
Fetch some data from the web using urllib • Go to the AR GIS User’s Forum site and pull down the conference program pdf (urllib) • Exercise-2.py • BS_Scrape.py • Fetching_Data_Example.py • Fetching_Get_DRGs_Example.py
text with complex patterns of characters • An incredibly complex topic • Simple ones can be sooooo helpful • re module in standard library * Patience required
code • import statement – call functionality in another module • Have one custom module (a .py file) with code you use all the time • Great way to package up helper functions • ESRI does this with ConversionUtils.py C:\Program Files (x86)\ArcGIS\Server10.0\ArcToolBox\Scripts
runs in background, so you get no console output • Great for timing processing and debugging • Append or write • Environment: dev/test/prod • Two options: – logging module – Just write out to text file
for Label Expressions in 10.1!!! • ArcPy – rich native Python site-package – Successor to arcgisscripting • Organized in tools, functions, classes, modules • Very well documented, but daunting • Must have Python 2.6! At least according to ESRI…
Bridge Inventory data – Fetch it – Parse it – Process it – Push to file geodatabase table – Push to file geodatabase featureclass • NBI_Data_Processing.py
– THE national US Python conference • FOSS4G – international open source for GIS • ESRI Developer Summit – major dork-fest, but great learning opportunity and Palm Springs in March
people • Komodo – free version also available • Notepad2 – ole’ standby editor • Notepad++ - people swear by it • PythonWin – another standby • …dozens (at least) more editors out there…