Articles tagged with python

  1. Getting Started With Pelican

    Posted on in Software

    I've been using WordPress on this site since 2007. After all this time, I've decided I want to try something new. So, I've decided to go in a completely different direction and start serving static content. There are three things driving my decision to change:

    • The existing site is really …
  2. [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 …

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

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

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

  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 …

Slaptijack's Koding Kraken