The Angry Apostrophe

I spent longer than I’d like to admit trying to figure out why my program bailed out when trying to parse a date. I assumed incorrectly that the part of the program trying to get date information was being fed data that didn’t include the date. So basically I thought that this line:

casemonth, caseday, caseyear = acase[‘Date Closed’].split(‘/’)

was getting passed a dict “acase” that didn’t have a value inside of ‘Date Closed’. I realized that the error I was getting would happen if I had anything in the ‘Date Closed’ value that didn’t match a date like “5/17/2012”, so I added a print line that would tell me what case it was currently parsing. Turns out it was choking on a specific one, and when I looked at the raw data I found this…

Yup. Right where a date was supposed to be is an apostrophe.

Here’s where things get relevant. Yesterday I posted about how I’m duplicating a lot of code in functions that are nearly identical. If I were to add some defensive code to one function to catch a non-compliant value in that field, I’d have to copy/paste it three times to the other similar functions. That’s not very efficient!

The solution for now is to just fix my raw data, but this has certainly been a sharp magnifying glass on my lack of code organization skills.

This entry was posted in Hobbies, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s