Simeon Franklin

Using Django's Multiple Database Support

In a recent Django class one of my students posed the problem she was learning Django to tackle - she would be responsible for writing a web-based administrative interface to a database whose structure she wasn't allowed to modify. Can Django do that?

Absolutely - and Django even comes with a management command to bootstrap working with a legacy database. Let's create a brand new project, use a popular sample database as our target, and using Django's multi-db support to store Django's built-in model data in a separate database.

Read More

Posted August 13th, 2012 in Django Python (Comment)

Understanding Python Decorators in 12 Easy Steps!

Ok, perhaps I jest. As a Python instructor decorators are a topic I find students consistently struggle with upon first exposure. That’s because decorators are hard to understand! Getting decorators requires understanding several functional programming concepts as well as feeling comfortable with some unique features of Python’s function definition and function calling syntax.

I can’t make decorators easy - but maybe by walking through each piece of the puzzle one step at a time I can help you feel more confident in understanding decorators[1]. Because decorators are complex this is going to be a long article - but stick with it! I promise to make each piece as simple as possible - and if you understand each piece, you’ll understand how decorators work!

Read More

Posted July 1st, 2012 in Python (Comment)

Javascript The Good Parts Talk

Modesto Scripting Languages Meetup is up to 22 members and 4 consecutive meetups!

Read More

Posted June 4th, 2012 in Programming (Comment)

What Generators are for

I teach Python classes and enjoy exploring language features from the perspective of newbie's to the language. Usually I can explain the rationale for Python language features by showing a compelling use case. But what about generator functions?

Read More

Posted May 22nd, 2012 in Programming Python (Comment)

Short tutorial on Django and Celery

I filmed a short tutorial on setting up a developer config of Celery with Django. Celery lets you call Python functions as asynchronous tasks, to be run by a separate process. Production usage of Celery involves installing a queue service of some kind (RabbitMQ, etc) but for development use it is possible to just use the Django ORM to store tasks in the database and run the celery daemon as a program in the foreground ala Django's runserver command. Video after the jump...

Read More

Posted April 26th, 2012 in Django Python (Comment)

Top 10 Rookie Mistakes in PHP

At the most recent Modesto Scripting Languages Meetup I presented a talk on the Top 10 Rookie Mistakes in PHP.

Read More

Posted April 26th, 2012 in Programming (Comment)

Fernando Perez and IPython at Baypiggies

Fernando Perez will be presenting at Baypiggies this coming Thursday (7:30 at Symantec Mountain View on Apr 19th, 2012). I'm a big fan of IPython and really enjoyed the IPython sessions I sat in @ PyCon2012 - come by and pick up IPython tips that will make you a more productive programmer daily!

Read More

Posted April 12th, 2012 in Python (Comment)

Getting started with Jython

A student in my Python Fundamentals class asked me to demonstrate how to get started with Jython - this is what I could figure out in 30 minutes...

Read More

Posted April 4th, 2012 in Python (Comment)

Pycon 2012

PyCon 2012 rocks. Dancing robots! Great tutorials, great talks, and 2,200+ Pythonistas!

Read More

Posted March 9th, 2012 in Python (Comment)

List Comprehensions for Modesto Scripting Languages Meetup

Monday night we had our second Modesto Scripting Languages Meetup. This was our first presentations-style meeting and all the presenters did a great job - James did a live demo of building a simple app in, Nathan covered the MVC pattern in web applications and I talked about list processing generally and list comprehensions in Python specifically.

Read More

Posted March 2nd, 2012 in Python (Comment)

Data Visualization with pyprocessing talk

Last Thursday I presented at Baypiggies. I have to say this was not one of my most polished presentations ever - I volunteered at the last minute when we didn't have a speaker. I had started a talk on the port of Processing to Python for PyCon and hadn't finished my sample programs or the talk structure when I didn't make the cut for PyCon. But taking my own advice not to waste a rejection I (sorta) finished up my talk in the couple of days before Baypiggies and filled in. Read More to see the slides and source code for the talk.

Read More

Posted February 28th, 2012 in Programming Python (Comment)

That's me, Python Expert

This is actually an announcement after the fact, but I am now a full time Python instructor for Marakana. Yes, my official job title is now Expert and instead of working as a freelance programmer I teach other programmers how to transition to Python. This has been a huge but welcome shift for me! Let me explain how I got here.

Read More

Posted February 14th, 2012 in Programming Python Technology (Comment)

Announcing the Modesto Scripting Language Meetup

Announcing the Modesto Scripting Languages Meetup. Central Valley Pythonistas, Rubyists, PHPers, etc all welcome.

Read More

Posted January 25th, 2012 in Programming Python (Comment)

Calling all PyCon Rejects

I recently received a very polite email from the PyCon program chair telling me what I already knew: my talk proposal didn't get accepted. My talk was rejected.

Let me explain how I already knew, why being rejected is not a bad thing, and why I'm challenging you to put your rejection to good use both personally and for the Python community.

Read More

Posted December 23rd, 2011 in Programming Python (Comment)

What is "Un-Pythonic"?

Tonight's Baypiggies topic is going to be What is Pythonic - Marilyn Davis is doing the presentation. I had a few thoughts but they're all in the opposite direction. I don't feel authoritative enough to define Pythonicness but as an instructor I frequently get to see code written by students new to Python that is obviously un-pythonic, for lack of a better term.

Read More

Posted December 15th, 2011 in Programming Python (Comment)

AHAH with Django and jQuery

I was recently asked about using AJAX via JQuery with Django and mentioned that I frequently use html fragments and a decorator to add Ajax functionality to existing views. Let's see how that works. (more after the jump).

Read More

Posted August 22nd, 2011 in Django Programming Python (Comment)

PDB Howto

Cool! See Max's awesome video editing skills render my pdb howto relatively stumble free! If you're curious about how to use the built in Python debugger this brief video tutorial should get you going.

Read More

Posted August 11th, 2011 in Programming Python (Comment)

The best way to OR a list of Django ORM Q objects

A co-worker asked me today about the best way to OR together a list of Q objects in the Django ORM. Usually you have a specific number of conditions and you can use Q objects and the bitwise OR operator to logical OR the query conditions together. The Q object is necessary because multiple arguments or successive calls to .filter are ANDed. But what if you have an arbitrary number of Q conditions?

One suggestion is to use the undocumented .add method of the Q object in a loop to add multiple query conditions together. I thought this might be a good use case for reduce and the operator module:

# Normal Usage with the | operator
from django.db.models import Q
qs = MyModel.objects.filter(Q(cond1=1) | Q(cond2="Y"))

#but given a list of Q conditions
from operator import __or__ as OR
lst = [Q(...), Q(...), Q(...)]
qs = MyModel.objects.filter(reduce(OR, lst))

Is this the most Pythonic approach?

Posted June 14th, 2011 in Programming (Comment)

Teaching Retrospective

As you can probably figure out from the last post, I have a new gig.

Thanks to the good folks at I recently taught a Python Fundamentals course in San Francisco.

This was my first time teaching for Marakana and I enjoyed the experience immensely - as did my students judging by their class reviews at the end! I had a blast and am looking forwards to more python classes, including an under-development Pro Django course. More details to come in this space - and thanks to Jas, Brenda, Mike, Chris, and Robert for being great first-time students. I hope you all go on to Pythonic success.

Posted June 14th, 2011 in Programming (Comment)

Python Fundamentals Resources

Deprecated: see the Python Fundamentals Page instead of this post

This will just be a grab bag of extra resources and notes for my students taking the Python Fundamentals Course at Marakana. Don't forget to grab the labs.

Additional Resources

Important Basics You Should Know

Python builtin functions: see the Or

import __builtin__

Keywords: see the docs Or

import keyword


Additional Documentation Referred to in Class

Don't forget the old labs - new labs and samples coming soon!

Posted May 30th, 2011 in Programming (Comment)

Older | Newer