An 0.1 todo command line script

I think I’m going to make an attempt at live-blogging this project. A post every day or two, with code snippets at least, maybe the full source because what do I give a crap about the source.

I DO need to install a code formatting plug-in for wordpress. Until then, code snippets are going to be just awful things wrapped in

<pre> tags.


After I posted that yesterday (which was actually a simple electronic journal entry that I finished and said “meh, post it”) I opened an editor and started dicking around with an interactive console-based python script, just to see how far I could go in one shot.

It’s funny because it has add/list/save/load functionality (automatically loading on startup, saving on add.) There’s no removal/mark as completed function yet.

But imMEDIATELY my brain started firing off in all kinds of funky directions.

So here’s the 0.1 version (well, it’s probably, but who’s counting.) It has the most basic functionality, and a non-interactive option for just spitting the list to stdout.

Call it with nothing enters the interactive command loop:

Call with ‘l’ (for list) and it’ll just spit the current todo list to stdout. l


import os
import sys

filename = 'todo.dat'
items = list()

def save_items():
    fh = open(filename,'w')
    for item in items:
        if item != '':
            print(item,file =fh)

def load_items():
    if not os.path.isfile(filename):
    fh = open(filename,'r')
    eof = False
    while not eof:
        line = fh.readline()
        if not line :
            eof = True

def add_item(foo):
    if len(foo) >2:
        item = ' '
        while item is not '':
            item = input("+ ")

def list_items():
    for item in items:

def complete_item(foo):
    item_to_complete = None
    if len(foo) >2:
        item_to_complete = int(foo[2:])
        del items[item_to_complete]

def command_loop():
    bail = False
    while not bail:

        foo = input("> ")

        if foo[0] == 'q' or foo[0] == 'Q':
            bail = True
        elif foo[0] == 'a':
        elif (foo[0] == 'c' or foo[0] == 'f'):
        elif foo[0] == 'l':
def run():

    if len(sys.argv) > 1:
        if sys.argv[1] == 'l':

if __name__ == '__main__':

So what’s this then? Here’s a script that maintains a local text file with a static name and gives you a couple commands (add, list, complete, quit) represented as one letter commands, to maintain a list, one item per line in the file. There’s a LOT wrong with it. BUT it works. It’s not production ready, and it’s particularly inelegant and it has no damn tests. All it’s supposed to be is a simple sketch, the code equivalent of a functional whiteboard diagram.

Next time I’ll either start ripping it apart for inclusion of more features, or for a serious restart. We’ll see. I’m still winging it.

Leave a Reply

Your email address will not be published. Required fields are marked *