Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีเปิดไฟล์ใน Binary Mode ด้วย Python

Binary files = ไฟล์ที่ไม่ใช่ readable characters (JPEG, GIF, MP3, Word, PDF) Python เปิด text mode default เพิ่ม 'b' ใน mode สำหรับ binary:

ตัวอย่าง

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

เปิด binary read mode เก็บเนื้อหาใน file_content