Articles tagged with python

  1. [Python] Convert String Date to Date Object

    Posted on in Programming

    Occasionally, you may run across a date in a format that can't be easily loaded into a Python date object. For example, I recently had a situation where a file I was parsing was full of dates in this format: 7/7/2008.

    The obvious thing to do here is …

  2. Empty Strings in Python Are False

    Posted on in Programming

    Recently I was working on some old code. One of my model methods was originally written such that if one parameter was set to the Python None type, a particular set of actions would occur. For some reason, I checked for None like this:

    if parameter is None:
        do something …
  3. The Beauty of Python File-like Objects

    Posted on in Programming

    As I mentioned the other day, I'm building a RADIUS client in Python for sending disconnect messages to Cisco routers.

    One hang-up with the pyrad package is that it requires a dictionary file in order to map RADIUS attribute names to codes and types. In the case of my client …

  4. [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

  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. 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 …

  7. 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 …

  8. Setup Help: Subversion for Your Pinax Project

    Posted on in Programming

    I recently began working on a project based on Pinax. The Pinax project's goal is to develop a set of re-usable applications for the Django Web Framework that are common in website development. Generally, these applications provide the functions and features common in social media sites. For reference, Bob Haugen …

Slaptijack's Koding Kraken