Entries Tagged with: Python
Debugging Python with pdb or ipdb
Python has a wonderful debugger called pdb you should use if you aren't already. If you're like me and prefer to not use an IDE, you could have a mess of print statements as you try to debug things. If you don't know about it, you should be using pdb. It makes debugging a far nicer experience.
Here's a little script I came up with to remove odd numbers from a list.
import unittest
def remove_odd_numbers():
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for item in my_list:
if item % 2 == 1:
my_list ...
Read More
Python for PHP Developers
I worked with Ryan Irelan at Mijingo to release a screencast for PHP developers who want to learn the basics of Python. If you fit in that boat, go check it out.
Read More
oAuth & the 37 Signals API
I started what was supposed to be a quick and fun Django project using the Basecamp API. The lack of documentation in their API makes me want to punch a litter of puppies. (This is a joke, puppies are the best)
To help prevent you from punching puppies and rather than trudge through their APIs Google Group, here's what I've figured out. I'm using Python Requests because it's fantastic. If you don't use it stop the insanity, and make your life easier by using it. Additionally, my code examples are within the context of Django ...
Read More
Site Updates
I pushed some updates to my site here earlier this week. Updated to Django rev 14870, implemented Xapian with Haystack, ditched categories and moved to django-taggit.
So here's a quick and simple Django template tag I came up with that reads the file modification time of css/javascript files and appends a v=n query string.
from django import template
from django.conf import settings
from os.path import join, getmtime
register = template.Library()
@register.simple_tag
def static_asset(filename):
"""
{% load static_asset %}
<link rel="stylesheet" href="{% static_asset "css/main.css" %}" type="text/css">
Renders a link like:
<link rel="stylesheet ...
Read More
Migrating Simple Desktops and Making it Rule - Part 1
Project Layout & Nginx
I worked with Kenny Meyers to move the kick-ass Simple Desktops website over to a new VPS and front static assets on EngineHosting's CDN. Kenny did the Django programming and it was a fun learning experience for us, as we moved from MySQL to Postgres and deployed with Chef, Gunicorn, Nginx and Fabric.
- Project Layout & Nginx
- Gunicorn & Supervisor
- Fabric
- Migrating from MySQL to Postgres
Project Layout
I had Kenny shuffle the project directory layout just a bit, we added the project specific configuration files in the config dir, pip requirements to the dependencies.txt file and application source files ...
Read More