Example #1
0
def write_to_text_file(text, path):
    ''' Writes text to file, where text is a string. '''

    try:

        data_utils.set_working_dir(path)
        '''Gets file name from path'''
        filename = os.path.basename(path)
        feature = open(filename, 'w')
        feature.write(text)
        feature.close()
        return True
    except IOError:
        print 'An exception occurred while saving the file'

    return False
Example #2
0
def write_to_text_file(text, path):
    ''' Writes text to file, where text is a string. '''

    try:

        data_utils.set_working_dir(path)
        '''Gets file name from path'''
        filename = os.path.basename(path)
        feature = open(filename, 'w')
        feature.write(text)
        feature.close()
        return True
    except IOError:
        print 'An exception occurred while saving the file'

    return False
Example #3
0
def read_file(input_file):
    '''
    Read a text file with filename as input_file.
    Return contents of file as string.
    '''
    try:
        if (data_utils.file_exist(input_file)):
            '''Sets current working directory to directory of
             input_file'''
            data_utils.set_working_dir(input_file)

            filename = data_utils.get_file_name_from_path(input_file)
            ''' Reads all data until EOF is reached,
            here bytes are returned as string object '''
            input = open(filename, 'r')
            return input.read()
    except IOError:
        print 'Error in opening or reading an input file'
        sys.exit()
Example #4
0
def read_file(input_file):
    '''
    Read a text file with filename as input_file.
    Return contents of file as string.
    '''
    try:
        if(data_utils.file_exist(input_file)):
            '''Sets current working directory to directory of
             input_file'''
            data_utils.set_working_dir(input_file)

            filename=data_utils.get_file_name_from_path(input_file)

            ''' Reads all data until EOF is reached,
            here bytes are returned as string object '''
            input = open(filename, 'r')
            return input.read()
    except IOError:
        print 'Error in opening or reading an input file'
        sys.exit()