Skip to content
nvkelso edited this page Aug 3, 2012 · 16 revisions

Very simple stuff here only.

  • PEP 8 - General formatting and structure guidelines.

  • Working with matrix math for doing geostats or image processing? Install NumPy and SciPy ».

Docs

Using a poorly documented library? Use the built in pydoc program by typing on the command line:

pydoc -p 8080

Then load in a web browser:

http://localhost:8080/

For instance, the docs for OGR is:

http://localhost:8080/osgeo.ogr.html

Sorting

http://wiki.python.org/moin/HowTo/Sorting

Importing CSVs as a dictionary

http://www.doughellmann.com/PyMOTW/csv/

Python operators

http://www.tutorialspoint.com/python/python_basic_operators.htm

  • Arithmetic Operators
  • Comparison Operators
  • Logical (or Relational) Operators
  • Assignment Operators
  • Conditional (or ternary) Operators

How do I import a python module given its relative path?

http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder

String formatting

http://stackoverflow.com/questions/1225637/python-string-formatting

http://docs.python.org/library/string.html#format-specification-mini-language

Variable and function scope

Python doesn't scope code to the local class automatically; you need to tell it to.

pp = self.foobar(arg1, arg2)

http://stackoverflow.com/questions/4068785/python-nameerror-global-name-foobar-is-not-defined

http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference

Using *args and **kwargs when calling a function

http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/

Using dicts to track and index counters

http://stackoverflow.com/questions/473099/python-how-to-check-if-a-given-index-in-a-dict-exists-yet

##Random

Clone this wiki locally