def open_r_encdetect(fname, readahead=1000):
    'Return a file object in read mode with auto-detected encoding\n\n    This is helpful when dealing with files of unknown encoding.\n\n    Parameters\n    ----------\n    readahead: int, optional\n      How many bytes to read for guessing the encoding type.  If\n      negative - full file will be read\n    '
    from chardet import detect
    import io
    with open(fname, 'rb') as f:
        head = f.read(readahead)
    enc = detect(head)
    denc = enc.get('encoding', None)
    lgr.debug('Auto-detected encoding %s for file %s (confidence: %s)', denc, fname, enc.get('confidence', 'unknown'))
    return io.open(fname, encoding=denc)
Return a file object in read mode with auto-detected encoding

This is helpful when dealing with files of unknown encoding.

Parameters
----------
readahead: int, optional
  How many bytes to read for guessing the encoding type.  If
  negative - full file will be read
def open_r_encdetect(fname, readahead=1000):
    'Return a file object in read mode with auto-detected encoding\n\n    This is helpful when dealing with files of unknown encoding.\n\n    Parameters\n    ----------\n    readahead: int, optional\n      How many bytes to read for guessing the encoding type.  If\n      negative - full file will be read\n    '
    from chardet import detect
    import io
    with open(fname, 'rb') as f:
        head = f.read(readahead)
    enc = detect(head)
    denc = enc.get('encoding', None)
    lgr.debug('Auto-detected encoding %s for file %s (confidence: %s)', denc, fname, enc.get('confidence', 'unknown'))
    return io.open(fname, encoding=denc)