def reopen_encoded(fileobj, mode='r', fallback_encoding=None):
    encoding = determine_encoding(fileobj.name, fallback_encoding)
    fileobj.close()
    return open(fileobj.name, mode, encoding=encoding)
Makes sure that a file was opened with some valid encoding.
dataset/ETHPy150Open c-w/Gutenberg/gutenberg/_util/os.py/reopen_encoded