useful python libraries ghislain prince. this presentation - standard libraries - “batteries...

14
Useful Python Libraries Ghislain Prince

Upload: caroline-smith

Post on 08-Jan-2018

222 views

Category:

Documents


0 download

DESCRIPTION

Regarding python 3 docs.python.org/2/library/2to3.html “Analyze tools for Pro” tool Future : pick you python (Conda)

TRANSCRIPT

Page 1: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

Useful Python LibrariesGhislain Prince

Page 2: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

This presentation

- Standard libraries- “batteries included”

- 3rd party libs

Page 3: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

Regarding python 3

• docs.python.org/2/library/2to3.html

• “Analyze tools for Pro” tool

• Future : pick you python (Conda)

Page 4: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

Standard Library is Large, powerful and Well-Documented

• docs.python.org• Installed with ArcGIS

Page 5: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

3rd Party Library

• Not part of standard library• Pypi – the Python Package Index

- 60,000+ packages- https://pypi.python.org/pypi- pip

• C:\>c:\Python27\ArcGIS10.3\Scripts\pip.exe install requests• Downloading requests-2.7.0-py2.py3-none-any.whl (470kB)• 100% |################################| 471kB 718kB/s• Installing collected packages: requests• Successfully installed requests-2.7.0

Page 6: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

Data Formats

• XML• JSON• CSV• Excel• PDF• Numpy/Pandas*• NetCDF

Page 7: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

3 XML options within the standard library

• SAX- Can handle huge datasets- Hard to use, verbose code

• DOM- Familiar: Javascript uses the DOM- Easy (ish)

• Etree- Feels like python- Extremely easy and concise for common tasks

Page 8: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

JSON

• json module

>>> import json>>> d = json.load(open("states.json", 'r'))>>> print(type(d))<class 'dict'>

Page 9: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

CSV & Excel

• csv module

>>> import csv>>> with open('eggs.csv', 'rb') as csvfile:... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')... for row in spamreader:... print ', '.join(row)Spam, Spam, Spam, Spam, Spam, Baked BeansSpam, Lovely Spam, Wonderful Spam

• xlrd & xlwt (third-party, included in ArcGIS)

Sample from python.org

Page 10: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

PDF

• arcpy.mapping.PDFDocument• reportlab (third-party)

- allows rapid creation of rich PDF documents, and also creation of charts in a varietyof bitmap and vector formats.

Page 11: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

Networking

• Calls to HTTP servers- urllib2- requests (third-party, pip-install)- asyncio

Page 12: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

Computing

• Numpy• Pandas *• Scipy *• Sympy *• R bridge (coming soon: github.com/R-ArcGIS … wait this isn’t python at all)

- * Pro 1.0 & planned for Desktop/Server 10.4

Page 13: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs

Resources

arcpy.wordpress.com

twitter.com/arcpy

desktop.arcgis.com/en/desktop/

Page 14: Useful Python Libraries Ghislain Prince. This presentation - Standard libraries - “batteries included” - 3 rd party libs