Pragmatic Development

Think before you do

Think before you do

I got a good lesson this week in why it’s necessary to think out the code, before you start coding. I’ve been working on learning Python as my general scripting language. Frankly I find it easier to understand than Perl. Anyway….I wrote a Python script to strip out a list of records from a mixed asset file. I thought to my self, it couldn’t really take that long. That’s what I thought…..

It end up taking several hours, and interruptions, to finish. What’s sad is, you would think it’s a complex script….but it isn’t. It’s fairly simple and probably would have taken anyone else minutes to crank it out. Ah well….it was still fun…

So as I sit down to read/prep for my assignments this week…I see that the assignment is to generate  structure code with UML. Suddenly, that task doesn’t seem as boring and useless as it used to last week.  Especially given the size of the Gradebook application we are creating.

 

The Python script that whooped my butt

# fixed assets remove retired
# this program removes the retired assets from the master list

import csv

# open files
masterReader = open('e:\\master.csv', 'r')
retireReader = open('e:\\retire.csv','r')
csvout = open("e:\\CSVOut.csv", "w")

# create readers and the writer
readMaster = csv.reader(masterReader)
readRetire = csv.reader(retireReader)
writer = csv.writer(csvout, dialect='excel')

retireList = []

# main

###### read retire asset number into a list
for asset in readRetire:
    retireList.append(asset[0])

#### read row from master file, compare asset number to retirement list
#### created above. if not in retirement list, write to output file
for row in readMaster:
    if row[0] not in retireList:
        writer.writerow(row)

# close open files
masterReader.close()
retireReader.close()
csvout.close()

Good Times I tell ya.

Garland MacNeill

About Garland MacNeill

Garland is a full time Systems Analyst for a school district in Tulsa, OK. Currently Garland is working on the completion of his masters degree from Capella University in Enterprise Software Architecture. In addition to working full time and going to school, Garland is married to his High School sweetheart Aj. Some of Garland's outside interests include motorcycles, spending time with nature, and enjoying the family cabin in Northern WI. In addition, Garland is also a fan of the Green Bay Packers and an avid fan of the Colorado Avalanche. He also enjoys watching MotoGP racing.