with open('testfile', 'wb') as fout:
    fout.write(''.join(map(chr, list(range(256)))))
with open('testfile') as fin:
    print('Opened in text mode is:', len(fin.read()))
with open('testfile', 'rb') as fin:
    pass
python - читать весь файл сразу