What am I missing in my script file? (line by line copy to the interpreter works)
<p>I'm working on the coursera data science course and making my first foray into python, and while respecting whitespace is driving me bonkers it's not too bad.</p>

<p>Even if there's not enough here to diagnos my problem maybe a savvy python programmer can open my eyes to the gottcha's I'm not even aware enough to google.</p>

<p>I've been trying to debug my script for some time to no avail. All the files and such are loading just fine but when I try and process a bunch of stored tweets and score them with a sentiment dictionary I get scores when I use the python interpreter but all zeros with my script. The difference is that in the script I put the execution chain in main() but at the CLI I'm executing line by line (though I did set up the relevant get_score function).</p>

<p>What I believe are the relevant lines:</p>

<pre><code>import sys
import json
import re

parse_words = re.compile("\W")
data = []
dictionary = {}

...

def get_score(tweet_text):
    words = parse_words.split(tweet_text.lower())
    word_scores = map(lambda word: dictionary.get(word, 0), words)
    score = sum(word_scores)
    return score


def main():
    """set up the data files"""
    ...
    for i in range(len(data)):
        try: # because not each line contains a tweet
            tweet_text = data[i]["text"].encode('utf-8')
        except:
            tweet_text = ""
        print("%6.2f %s" % (get_score(tweet_text), tweet_text))
</code></pre>
