'''
Created on Sep 26, 2011

@author: rodger
'''
# must include these imports to use the file chooser
import os
import tkFileDialog

    
def choose_file_to_open():
    """
    prompt for existing file, return the file (open for reading)
    """
    file = tkFileDialog.askopenfile(title="choose a file", initialdir=os.getcwd())
    return file


def joinTogether(mylist, separator):
    # TODO: convert the list mylist into a string of items from 
    #        mylist separated by separator
    answer = ''
    for item in mylist:
        answer += item + separator
    return answer.strip(separator)
    '''
    if len(mylist) == 0:
        return ''
    answer = mylist[0]
    for num in range(1,len(mylist)):
        answer += separator + mylist[num]
    return answer
    '''



def processLine(line):
    words = line.split()   # put the words into a list
    # TODO: create a new list of words whose length is greater than 4
    #       return a string of the words whose length is greater than 4
    #       with a blank separating pairs of the words
    '''
    answerlist = []
    for word in words:
        if len(word)>4:
            answerlist.append(word)
    return (joinTogether(answerlist, ":"))
    '''
    return joinTogether([word for word in words if len(word)>4], ':')
     

def processFile(file):
    '''
    process the lines in a file
    in this case we just print them
    '''
    for line in file:
        print processLine(line)
        
processFile(choose_file_to_open())        