'''
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):
    # TODODone: convert the list mylist into a string of items from 
    #        mylist separated by separator
    if len(mylist)== 0:
        return ""
    answer = mylist[0]    
    for someword in range(1,len(mylist)):
        answer = answer + " " + mylist[someword]
    return answer

def processLine(line):
    # TODODone: create a new list of words whose length is greater than 4
    words = line.split()   # put the words into a list
    answerlist = []     # create a new list
    for word in words:
        if len(word)>4:
            answerlist.append(word)
    return joinTogether(answerlist," ")

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())        