Checks if a file is a text file

def _is_text_file(filename):
    '''
    Checks if a file is a text file
    '''
    type_of_file = os.popen('file -bi {0}'.format(filename), 'r').read()
    return type_of_file.startswith('text')