Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách mở file binary mode Python?


File "nhị phân" format không phải ký tự đọc được: JPEG/GIF, MP3, Word/PDF. Python mở text mode mặc định. Mở binary mode, thêm 'b' vào mode.

Ví dụ

f = open('my_file.mp3', 'rb')
file_content = f.read()
f.close()

Mở my_file.mp3 binary read mode, lưu content vào biến.