PyOhio 2012

Last month, I had the great fortune to attend my very first conference: PyOhio. There were many great talks and opportunities to meet interesting people. What follows are some personal notes I took during the conference. (It took awhile because the way I took notes was very incongruous with WordPress.  Lots of reformatting before editing. Lesson for next time friends.)

Django bootcamp

The best thing I got out of this presentation by Raymond Chandler was setting up a basic development environment on Ubuntu and getting comfortable with git and virtualenv in a Linux environment.  Then we progressed to build a basic twitter clone called ‘chirp’.

setting up a development environment:

sudo apt-get install git
pip install django
pip install virtualenv


virtualenv [name]
source [name]/bin/activate
pip install django  (installs within the environment)

setting up app

As part of the process of setting up a Django App, Raymond suggested renaming the project app directory to “config” (a rails convention), which I kind of like: starproject chirp
mv chirp/ config ## rails convention
  • edit to change os.environ.(…) settings
  • edit chirp/config/ to change [app name] to config


Getting a new git repository started for the demo app “chirp”…

python2 startapp chirp
git init
touch .gitignore
[edit .gitignore]
git add .gitignore
git status
git add --all
git commit -m "commit message"

git remote add origin [location]
git push -u origin master
-u: makes repo you are pushing to the athoritative copy

git checkout -b adding-chirp-model


  • django command extensions
  • tastypy :: restful web services app
  • python inspectdb :: assimilates database, creates model
  • vim plugins: nerdtree, miniBufEx
  • help([module]plorer)

Ray Chandler explaining Django’s Model-View-Controller(template) architecture.

Presentation notes can be found here:



assert 1==2, “Reality Check”

python -i #provides interactive debugger
python -o #switch to deactivate assertions
python -m unittest [module[.TestClass[.assertion]]] #switch to load module

unittest module

import unittest
dir(unittest)   # list out methods
subclass unittest.TestCase
– you add methods called test
– supply assert* methods

unittest output:

  • (period): successful
  • F: Failed
  • E: Error in assertion

outcomes accumulated in unittest.TestResult instance

can create multiple subclasses and create testsuites
str_suite = unittest.TestSuite()

Test fixture: tests + suites + Setup + teardown

pip install distribute


python -m doctest pycampNG/

– inspects file for doc strings and constructs and attempts to execute code

doctest.testmod() # runs all test in specified module
doctest.DocTestSuite() converts doctests to a unittest.TestSuite instance.
– reference in

Lightning talks 1

Brandon Rhodes: Python Patterns 1

1977 Architect Christopher Alexander
– Pattern at one level of detail, apply it to any scale.
“Gang of Four”: Gamma, Helm, Johnson, Vlissides :: Elements of reusable Object design

Not all patterns are OO patterns:

  •  dictionary has a get(key, default) method.
  •  continue: break out an iteration of a for loop, continue on to the next iteration

– Python’s dynamic features makes OO patterns disappear

builder design patterns

  • python doesn’t have separate syntax for instantiating objects
  • most “creational oo patterns” are contortions to avoid making brittle ‘new’ calls in c++ and java
  • python singleton pattern: wrap in method generator.
  • ‘copy’ module can introspect and make a copy of an object
  •  lxml.builder import E :: ‘framework-y’

structural patterns

Adapter: wrapper to add a method.  Examples:

  • sockets send/receive rather than read/write.
  • socket._fileobject adopter
  • crucial pattern for letting us re-use code


  • Gary Bernhart: “have modules that do nothing but persist information. Separate your business logic into functions that take data objects”

Composite: “if a module imports 3 major libs or frameworks, refactor into 2 modules each of which only imports 2 libraries”

Facade: an object that hides a structure.

Flyweight pattern: only create single instance of static data


  • An obj that wraps another obj, like adapter, but accepts the same methods as the wrapped class.
  • ex: remote procedure calls

Decorator (not like the python decorators)

  • tend to appear in ‘glue’ code

behavioral patterns

  • Chain of responsibility
  • Command: wrap, track history, enable undo
  • Interpreter: domain specific languages
  • Iterator/generator:  “most important addition of the 2000’s”
  • Mediator
  • Memento
  • Observer
  • State, template, visitor
  • most of these turn up in bigger projects


Python programmers rarely meet the bigger patterns because python programmers tend to write smaller programs and scripts.  Frameworks have already implemented them.

Python for humans

presenter: @kennethreitz
works for Heroku

“open source encourages best practices”

zen of python:

  • Explicit is better than implicit
  • Simple is better than complex
  • Complex is better than complicated
  • If the implementation is hard to explain, it’s a bad idea

Barriers to entry

Other python examples:

  • Packaging & Dependencies
  • Date/Times
  • Unicode
  • Testing
  • Dependencies

Hitchhikers guide to python – an opinionated best practices guide to installing and using python.


“There should be one – and preferably only one – obvious way to do something” – more python zen


Presenter: Andrew Schowen – @andrewschoen


Andrew’s demo:

You can edit content (templates/plugins) within the context of your page

  • create the pages in the menus at the same time.
  • internationalized

Structure: templates, placeholders, menus

Plugins: Yes! Plugins are available.  You can also easily write custom plugins using other Django app/model

apphooks: direct through djangocms to the app. templates make for abstract skinning.  CMS app puts ‘polls’ in the menu.

Extensions and 3rd party apps

  • django-filer: image manager
  • cmsplugin-filer
  • django-reversion: lets you version control page data
  • cmsplugin-blog
  • django-cms-redirects: lets you manage (303, 410) errors

Lightning Talks 2

  • Bookie
  • Data Science with Python
  • MaximinProject
    • people know poverty exists, but don’t know much about it or where it is.
    • human wealth index
    • non profit to build website to connect funders with groups on the ground
  • Dependency Injection – A Python Patterns Encore
    • Brandon Rhodes
    • @brandon_rhodes
    • “if i define it, i can’t be wrong”
    • ex: urlopen – add a parameter to pass real object or some simple test function
    • pass in the callable function rather than chaining function calls.
  • From Python Import Podcast
  • Dynamic DNS
    • @catherinedevlin
    • URL:- SQL access to a healthcare database
    • API for python

I’m looking forward to catching the other amazing presentations I missed on

Update: The videos have been posted to


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s