nemorathwald: (sinfest devil clerk)
[personal profile] nemorathwald
I'm dog-sitting my landlady's puppy, a half-spaniel/half-coton named Lola. Lola is so young she couldn't even walk a few days ago. In the Python programming language, the object "lola" is in the class Dog and has methods such as "lola.eat" and "lola.white". Bruce Webber explained this to me last night when we continued my instruction in Python. We completed all the steps I had planned out for what to do in my program Herdcat. Then he taught me the basics of Functions and Objects.

#!/usr/bin/python
import datetime

class Contact:
    def __init__(self, name, projects, interval, reminder):
        self.name = name
        self.projects = projects
        self.interval = datetime.timedelta(int(interval))
        datepart = reminder.split('/')
        self.reminder = datetime.date(int(datepart[2]), int(datepart[0]), int(datepart[1]))
    def isdue(self):
        if self.reminder < datetime.date.today():
            return True
        else:
            return False

def readrolodex():
    #'r' stands for 'read'
    herdcatfile = file('herdcat.txt','r')
    rolodex = []
    source = herdcatfile.readlines()
    herdcatfile.close()
    for row in source:
        contactpart = row.strip().split('|')
        rolodex.append(Contact(contactpart[0], contactpart[1], contactpart[2], contactpart[3]))
    return rolodex

def writerolodex(rolodex):
    #'w' stands for 'write'
    herdcatfile = file('herdcat.txt', 'w')
    for contact in rolodex:
        herdcatfile.write('%s|%s|%s|%s\n' % (contact.name, 
                contact.projects, contact.interval.days, contact.reminder.strftime('%m/%d/%Y')))
    herdcatfile.close()

rolodex = readrolodex()
for contact in rolodex:
    if contact.isdue():
        print 'Has %s responded to you about %s since the last Reminder?' % (contact.name, contact.projects)
        smartass = True
        while smartass:
            response = raw_input('Y/N:')
            if response.upper() == 'Y':
                #int() stands for 'make this string an integer'
                contact.interval = contact.interval + datetime.timedelta(2)
                smartass = False
            elif response.upper() == 'N':
                contact.interval = contact.interval - datetime.timedelta(1)
                smartass = False
            else:
                print 'You did not type Y or N, please try again:'
        contact.reminder = contact.reminder + contact.interval
    print 'Name: %s\nProjects: %s\nInterval: %s\nReminder: %s' % (contact.name, 
            contact.projects, contact.interval, contact.reminder.strftime('%m/%d/%Y'))
writerolodex(rolodex)

The current contents of herdcat.txt:
Bruce Webber|Python, Lojban, Penguicon, hanging out|7|07/17/07
Tim Schmidt|Penguicon, Stepmania rig, RepRap|7|07/18/07
Gerald Gentry|Subgenius at Penguicon, Budget for Stepmania, next SMOS Party|7|07/18/07
Chris DiBona|Inviting software guests|7|07/16/07
Frank Hayes|Getting my article published in a Linux magazine|7|04/20/07

Date: 2007-07-26 06:04 pm (UTC)
From: [identity profile] atropis.livejournal.com
in computer context, lola is only one letter away from lol. i guess that mkaes it an unusually happy name?

Date: 2007-07-26 06:34 pm (UTC)
From: [identity profile] matt-arnold.livejournal.com
That's appropriate! She's an unusually happy dog!

Date: 2007-07-29 04:49 pm (UTC)
From: [identity profile] eilrahc.livejournal.com
Weeeelll, technically lola.white would be an object property rather than a method. :) This sounds like a fun first project. I'm currently writing a personal address book to teach myself (more of) PHP.

March 2026

S M T W T F S
1234567
89 1011121314
15161718192021
22232425262728
293031    

Most Popular Tags