def smartopen(fileHandle, mode='r'):
    """Return an open file object, if passed a filename;
    otherwise just return the object.
    
    @param fileHandle: Input or output file or filename
    @param mode: IO mode ('r', 'w', ...)
    @return: the open file object
    """
    if type(fileHandle)==str:
        ioFile = open(fileHandle, mode)
        return ioFile
    else:
        return fileHandle