'''
Created on Nov 1, 2010

@author: rcd
'''
import tkFileDialog
import urllib


def get_file (name=''):
    """
    Get a file for reading
    Files can come from a variety of sources:
    - internet, via URL
    - local computer, via file name
    - local computer, chosen by the user
    """
    if name == '':
        return tkFileDialog.askopenfile()
    elif name.startswith('http'):
        return urllib.urlopen(name)
    else:
        return open(name)

def get_lines (file):
    """
    Given a file, read it line by line and return a list of all the lines.
    Note, this function closes the file before returning --- it will need 
      to be opened again before using it again
    """
    result = [line.strip() for line in file.readlines()]
    file.close()
    return result

def get_words (file):
    """
    Given a file, read it word by word and return a list of all the words.
    Note, this function closes the file before returning --- it will need 
      to be opened again before using it again
    """
    result = file.read().split()
    file.close()
    return result
