Articles tagged with python

  1. [Python] Remove Whitespace From a String

    Posted on in Programming

    >>> print "".join(" hello   world ".split())
    helloworld
    

    The key to the above is that split() separates the string on any amount of whitespace when no separator is specified.

    python

  2. Your Django manage.py ImportError May be a Syntax Problem

    Posted on in Programming

    Django LogoBackground: While cleaning up my development directory the other day, I renamed one of my Django project directories to the domain name of the site. For the sake of argument, we'll call it django.slaptijack.com. When I descended into the directory and tried to start the development server, I …

  3. Django 1.2 is on the way

    Posted on in Programming

    Django LogoIf you're like me, you're probably really excited about the changes coming in Django 1.2. The good news is that, as of April 7th, there are only 14 outstanding issues in the Django 1.2 release candidate. Of those 14 remaining issues, it sounds like one in particular is …

  4. Limit ForeignKey to Staff Users in Django

    Posted on in Programming

    Django Logo If you've ever built a site that has different kinds of users, you've probably run across the case where you want a limited number of users to appear in a particular list. For example, you may only want staff members to be assigned ownership of a particular object. If your …

  5. No such table: django_admin_log

    Posted on in Programming

    If you get this error when trying to save something in the Django admin, it's probably because you forgot to synchronize the database after adding the admin application. If you are using a pre-1.2 version of Django, you can simply:

    $ ./managy.py syncdb
    

    Django 1.2 (which is currently …

  6. Python CSV error on new-line character in unquoted field

    Posted on in Programming

    FYI, this post is out of date. As of Python 3.0, universal newline mode is now the default and 'U' is accepted, but no longer does anything.

    I deal with a lot of people that prefer to open reports in Microsoft Excel. I've gotten used to generating CSV (comma …

  7. Sorting dictionary keys in Python

    Posted on in Programming

    For some reason, sorting a dictionary by its keys seems to be one of the most frequently asked Python questions. I'm not sure if this is because it's just much easier to do in other languages, or if the semantics of the language just confuse new Python developers. I guess …

  8. Filtering Queries in Django Templates

    Posted on in Programming

    Django LogoIn a word, you can't.

    Django was designed to keep the template system separate from the coding. This means that Django templates are mostly HTML with a bit of Django template code interspersed. This is very different from PHP where HTML and code are very tightly bound. Separating HTML development …

  9. Pinax's New Directory Structure

    Posted on in Programming

    If you've been following along, you are probably already aware the Pinax team has decided to make some radical changes to their directory structure based on input from users. I took the time to update my own Pinax project — let me show you what's changed.

    First, here's the new directory …

My Bookshelf

Reading Now

Other Stuff