Python File Processing with stdlib, Pandas, Pillow, pypdf and openpyxl Across 54 Formats: Questions and Answers

Engineering reference answering 100 distinct technical questions on reading, validating, streaming, and writing all 54 file formats in Python 3 using standard library modules and production packages without memory leaks across all 54 file formats supported by SampleTestFiles.

Representative format hubs and diagnostic tools

Part 1: Document, spreadsheet and text format questions

1. How do I read and validate a .avro (Avro) file in Python 3 while keeping memory usage bounded?
Open sample-avro-1kb.avro in binary mode ('rb'), verify the leading signature (4F 62 6A 01), and parse sample-avro-1kb.avro (1,024 bytes, SHA-256 a53b9283c084120f…) using Apache Avro (Java/C++/Python) for Apache Kafka event schema evolution.
2. How do I read and validate a .bin (BIN) file in Python 3 while keeping memory usage bounded?
Open sample-bin-1kb.bin in binary mode ('rb'), verify the leading signature (None), and parse sample-bin-1kb.bin (1,024 bytes, SHA-256 bb174eca55fcab7b…) using xxd for S3 multipart chunk testing.
3. How do I read and validate a .bmp (BMP) file in Python 3 while keeping memory usage bounded?
Open sample-bmp-10kb.bmp in binary mode ('rb'), verify the leading signature (42 4D), and parse sample-bmp-10kb.bmp (10,240 bytes, SHA-256 d7833ceeb6df6a3f…) using Windows GDI/WIC for and Windows GDI clipboard interoperability.
4. How do I read and validate a .css (CSS) file in Python 3 while keeping memory usage bounded?
Open sample-css-1kb.css in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-css-1kb.css (1,024 bytes, SHA-256 d66dd341e097bfbf…) using esbuild for bundler/minifier benchmarks.
5. How do I read and validate a .csv (CSV) file in Python 3 while keeping memory usage bounded?
Open sample-csv-1kb.csv in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-csv-1kb.csv (1,024 bytes, SHA-256 cdddf7fab2967f74…) using and PostgreSQL COPY for CRM contact imports.
6. How do I read and validate a .docx (DOCX) file in Python 3 while keeping memory usage bounded?
Open sample-docx-50kb.docx in binary mode ('rb'), verify the leading signature (50 4B 03 04), and parse sample-docx-50kb.docx (51,200 bytes, SHA-256 f035af1f12c5f378…) using python-docx for resume parsers.
7. How do I read and validate a .eml (EML) file in Python 3 while keeping memory usage bounded?
Open sample-eml-1kb.eml in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-eml-1kb.eml (1,024 bytes, SHA-256 fcb83c22ab1b25f4…) using Nodemailer/mailparser for helpdesk ticket email-to-case ingestion.
8. How do I read and validate a .epub (EPUB) file in Python 3 while keeping memory usage bounded?
Open sample-epub-10kb.epub in binary mode ('rb'), verify the leading signature (50 4B 03 04), and parse sample-epub-10kb.epub (10,240 bytes, SHA-256 7aeb3a14b30fc59f…) using epub.js for and accessibility screen-reader testing.
9. How do I read and validate a .flac (FLAC) file in Python 3 while keeping memory usage bounded?
Open sample-flac-100kb.flac in binary mode ('rb'), verify the leading signature (66 4C 61 43), and parse sample-flac-100kb.flac (102,400 bytes, SHA-256 7d5b1004d60d26ed…) using FFmpeg for and bit-exact decoder verification.
10. How do I read and validate a .geojson (GeoJSON) file in Python 3 while keeping memory usage bounded?
Open sample-geojson-1kb.geojson in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-geojson-1kb.geojson (1,024 bytes, SHA-256 9be0172ddbe0d3f7…) using Mapbox GL / MapLibre for GIS boundary imports.
11. How do I read and validate a .gif (GIF) file in Python 3 while keeping memory usage bounded?
Open sample-gif-10kb.gif in binary mode ('rb'), verify the leading signature (47 49 46 38 39 61), and parse sample-gif-10kb.gif (10,240 bytes, SHA-256 66c85de4a8d004e4…) using FFmpeg for legacy 8-bit palette tests.
12. How do I read and validate a .gltf (glTF) file in Python 3 while keeping memory usage bounded?
Open sample-gltf-1kb.gltf in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-gltf-1kb.gltf (1,024 bytes, SHA-256 00005d45316577b7…) using Babylon.js for and game asset validation pipelines.
13. How do I read and validate a .gpx (GPX) file in Python 3 while keeping memory usage bounded?
Open sample-gpx-1kb.gpx in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-gpx-1kb.gpx (1,024 bytes, SHA-256 753bd5be3339a3bc…) using Strava/Garmin importers for fitness-tracker activity uploads.
14. How do I read and validate a .gz (GZ) file in Python 3 while keeping memory usage bounded?
Open sample-gz-1kb.gz in binary mode ('rb'), verify the leading signature (1F 8B 08), and parse sample-gz-1kb.gz (1,024 bytes, SHA-256 d67bc6e2b98c4e46…) using libdeflate for log compression pipelines.
15. How do I read and validate a .html (HTML) file in Python 3 while keeping memory usage bounded?
Open sample-html-1kb.html in binary mode ('rb'), verify the leading signature (3C 21 44 4F 43 54 59 50 45), and parse sample-html-1kb.html (1,024 bytes, SHA-256 eabca5a92fca425f…) using Browser HTML5 engines (Blink for email template sanitizers.
16. How do I read and validate a .ico (ICO) file in Python 3 while keeping memory usage bounded?
Open sample-ico-10kb.ico in binary mode ('rb'), verify the leading signature (00 00 01 00), and parse sample-ico-10kb.ico (10,240 bytes, SHA-256 deterministic…) using and Windows Shell icon extractors for website favicon.ico validators.
17. How do I read and validate a .ics (iCalendar) file in Python 3 while keeping memory usage bounded?
Open sample-ics-1kb.ics in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-ics-1kb.ics (1,024 bytes, SHA-256 b53dd9960c400e35…) using ical.js for booking confirmation attachments.
18. How do I read and validate a .ini (INI) file in Python 3 while keeping memory usage bounded?
Open sample-ini-1kb.ini in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-ini-1kb.ini (1,024 bytes, SHA-256 58c71755af8a90ba…) using PHP parse_ini_file for Git .gitconfig files.
19. How do I read and validate a .jpg (JPG) file in Python 3 while keeping memory usage bounded?
Open sample-jpg-1kb.jpg in binary mode ('rb'), verify the leading signature (FF D8 FF), and parse sample-jpg-1kb.jpg (1,024 bytes, SHA-256 8ee87ac7e59dde63…) using libjpeg-turbo for EXIF scrubbers.
20. How do I read and validate a .js (JavaScript) file in Python 3 while keeping memory usage bounded?
Open sample-js-1kb.js in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-js-1kb.js (1,024 bytes, SHA-256 3555814484c57fa1…) using Acorn for and upload denylist verification.
21. How do I read and validate a .json (JSON) file in Python 3 while keeping memory usage bounded?
Open sample-json-1kb.json in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-json-1kb.json (1,024 bytes, SHA-256 e6b79ec0b9d43a78…) using Jackson (Java) for REST API request/response validation.
22. How do I read and validate a .jsonl (JSONL) file in Python 3 while keeping memory usage bounded?
Open sample-jsonl-1kb.jsonl in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-jsonl-1kb.jsonl (1,024 bytes, SHA-256 c68974416de0b42c…) using Vector for BigQuery/Snowflake bulk streaming loads.
23. How do I read and validate a .kml (KML) file in Python 3 while keeping memory usage bounded?
Open sample-kml-1kb.kml in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-kml-1kb.kml (1,024 bytes, SHA-256 405296fc546173a0…) using QGIS for Google Earth exports.
24. How do I read and validate a .log (LOG) file in Python 3 while keeping memory usage bounded?
Open sample-log-1kb.log in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-log-1kb.log (1,024 bytes, SHA-256 41cbef53cbcb07bf…) using and Grafana Loki for and compression ratio benchmarks.
25. How do I read and validate a .m4a (M4A) file in Python 3 while keeping memory usage bounded?
Open sample-m4a-100kb.m4a in binary mode ('rb'), verify the leading signature (66 74 79 70 4D 34 41 20 at byte offset 4), and parse sample-m4a-100kb.m4a (102,400 bytes, SHA-256 36b04a984c79c348…) using and HTML5 <audio> elements for mobile voice-memo uploads.

Part 2: Image, audio, video, archive and 3D format questions

1. How do I read and validate a .md (Markdown) file in Python 3 while keeping memory usage bounded?
Open sample-md-1kb.md in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-md-1kb.md (1,024 bytes, SHA-256 8c04ab877ffd78d2…) using markdown-it for Hugo.
2. How do I read and validate a .mkv (MKV) file in Python 3 while keeping memory usage bounded?
Open sample-mkv-100kb.mkv in binary mode ('rb'), verify the leading signature (1A 45 DF A3), and parse sample-mkv-100kb.mkv (102,400 bytes, SHA-256 bbd4d0d69f551e34…) using FFmpeg for and transcoding worker input testing.
3. How do I read and validate a .mov (MOV) file in Python 3 while keeping memory usage bounded?
Open sample-mov-100kb.mov in binary mode ('rb'), verify the leading signature (66 74 79 70 71 74 20 20 at byte offset 4), and parse sample-mov-100kb.mov (102,400 bytes, SHA-256 a79364ccad697070…) using and DaVinci Resolve / Premiere for iOS/macOS screen-recording uploads.
4. How do I read and validate a .mp3 (MP3) file in Python 3 while keeping memory usage bounded?
Open sample-mp3-100kb.mp3 in binary mode ('rb'), verify the leading signature (49 44 33), and parse sample-mp3-100kb.mp3 (102,400 bytes, SHA-256 f485bac1a1c6c218…) using MediaInfo for podcast hosting platforms.
5. How do I read and validate a .mp4 (MP4) file in Python 3 while keeping memory usage bounded?
Open sample-mp4-100kb.mp4 in binary mode ('rb'), verify the leading signature (66 74 79 70 at byte offset 4), and parse sample-mp4-100kb.mp4 (102,400 bytes, SHA-256 60dec7b5883beb89…) using and browser HTMLVideoElement for social-media video uploaders.
6. How do I read and validate a .obj (OBJ) file in Python 3 while keeping memory usage bounded?
Open sample-obj-1kb.obj in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-obj-1kb.obj (1,024 bytes, SHA-256 50571a2608db70d5…) using Three.js OBJLoader for game-engine asset importers.
7. How do I read and validate a .ods (ODS) file in Python 3 while keeping memory usage bounded?
Open sample-ods-10kb.ods in binary mode ('rb'), verify the leading signature (50 4B 03 04), and parse sample-ods-10kb.ods (10,240 bytes, SHA-256 bef615f4c17ff3f9…) using and Collabora Online for cross-suite Calc/Excel compatibility checks.
8. How do I read and validate a .odt (ODT) file in Python 3 while keeping memory usage bounded?
Open sample-odt-10kb.odt in binary mode ('rb'), verify the leading signature (50 4B 03 04), and parse sample-odt-10kb.odt (10,240 bytes, SHA-256 5d076b5d70f3b35c…) using Collabora Online for and ISO/IEC 26300 compliance testing.
9. How do I read and validate a .pdf (PDF) file in Python 3 while keeping memory usage bounded?
Open sample-pdf-5kb.pdf in binary mode ('rb'), verify the leading signature (25 50 44 46 2D), and parse sample-pdf-5kb.pdf (5,120 bytes, SHA-256 065325468ac444eb…) using pypdf for invoice generators.
10. How do I read and validate a .png (PNG) file in Python 3 while keeping memory usage bounded?
Open sample-png-1kb.png in binary mode ('rb'), verify the leading signature (89 50 4E 47 0D 0A 1A 0A), and parse sample-png-1kb.png (1,024 bytes, SHA-256 7f4bf91380e02b39…) using pngcheck for OCR preprocessing.
11. How do I read and validate a .pptx (PPTX) file in Python 3 while keeping memory usage bounded?
Open sample-pptx-100kb.pptx in binary mode ('rb'), verify the leading signature (50 4B 03 04), and parse sample-pptx-100kb.pptx (102,400 bytes, SHA-256 57d931827d83c96d…) using and Google Slides importer for and presentation thumbnail extractors.
12. How do I read and validate a .rtf (RTF) file in Python 3 while keeping memory usage bounded?
Open sample-rtf-1kb.rtf in binary mode ('rb'), verify the leading signature (7B 5C 72 74 66 31), and parse sample-rtf-1kb.rtf (1,024 bytes, SHA-256 7359e23a983cc8fe…) using Microsoft Word for cross-platform rich-text editors.
13. How do I read and validate a .sql (SQL) file in Python 3 while keeping memory usage bounded?
Open sample-sql-1kb.sql in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-sql-1kb.sql (1,024 bytes, SHA-256 c69482bb915813ee…) using psql (PostgreSQL) for backup-restore smoke tests.
14. How do I read and validate a .srt (SRT) file in Python 3 while keeping memory usage bounded?
Open sample-srt-1kb.srt in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-srt-1kb.srt (1,024 bytes, SHA-256 854da70417fd63ce…) using pysrt for and muxing tests with MKV/MP4 containers.
15. How do I read and validate a .stl (STL) file in Python 3 while keeping memory usage bounded?
Open sample-stl-1kb.stl in binary mode ('rb'), verify the leading signature (73 6F 6C 69 64), and parse sample-stl-1kb.stl (1,024 bytes, SHA-256 6fc6b99eb04a89de…) using Cura for and CNC quotation portals.
16. How do I read and validate a .svg (SVG) file in Python 3 while keeping memory usage bounded?
Open sample-svg-1kb.svg in binary mode ('rb'), verify the leading signature (3C 73 76 67), and parse sample-svg-1kb.svg (1,024 bytes, SHA-256 ed384263be1c983b…) using SVGO for responsive icon systems.
17. How do I read and validate a .tar (TAR) file in Python 3 while keeping memory usage bounded?
Open sample-tar-10kb.tar in binary mode ('rb'), verify the leading signature (75 73 74 61 72 at byte offset 257), and parse sample-tar-10kb.tar (10,240 bytes, SHA-256 4c6ff6563d9c00f0…) using bsdtar (libarchive) for and streaming archive extraction without random seeks.
18. How do I read and validate a .tiff (TIFF) file in Python 3 while keeping memory usage bounded?
Open sample-tiff-10kb.tiff in binary mode ('rb'), verify the leading signature (49 49 2A 00), and parse sample-tiff-10kb.tiff (10,240 bytes, SHA-256 b7bfb311950ba844…) using libtiff for multi-page fax ingestion.
19. How do I read and validate a .toml (TOML) file in Python 3 while keeping memory usage bounded?
Open sample-toml-1kb.toml in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-toml-1kb.toml (1,024 bytes, SHA-256 c77a799450a2b039…) using and Taplo for and CLI tool configuration files.
20. How do I read and validate a .tsv (TSV) file in Python 3 while keeping memory usage bounded?
Open sample-tsv-1kb.tsv in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-tsv-1kb.tsv (1,024 bytes, SHA-256 1da1f9e2460c95d7…) using and DuckDB for bioinformatics matrices.
21. How do I read and validate a .txt (TXT) file in Python 3 while keeping memory usage bounded?
Open sample-txt-1kb.txt in binary mode ('rb'), verify the leading signature (None), and parse sample-txt-1kb.txt (1,024 bytes, SHA-256 330c0c29155c03a0…) using Python io.TextIOWrapper for line-ending normalization (LF vs. CRLF).
22. How do I read and validate a .vtt (WebVTT) file in Python 3 while keeping memory usage bounded?
Open sample-vtt-1kb.vtt in binary mode ('rb'), verify the leading signature (57 45 42 56 54 54), and parse sample-vtt-1kb.vtt (1,024 bytes, SHA-256 58689e501f1d3e9f…) using Video.js for HLS/DASH segmented subtitle tracks.
23. How do I read and validate a .wav (WAV) file in Python 3 while keeping memory usage bounded?
Open sample-wav-100kb.wav in binary mode ('rb'), verify the leading signature (52 49 46 46 ?? ?? ?? ?? 57 41 56 45), and parse sample-wav-100kb.wav (102,400 bytes, SHA-256 46a36cb64427f37a…) using and Web Audio decodeAudioData for and lossless audio reference checks.
24. How do I read and validate a .webm (WebM) file in Python 3 while keeping memory usage bounded?
Open sample-webm-100kb.webm in binary mode ('rb'), verify the leading signature (1A 45 DF A3), and parse sample-webm-100kb.webm (102,400 bytes, SHA-256 f30a216fe3ae1225…) using MediaInfo for royalty-free HTML5 video playback.
25. How do I read and validate a .webp (WebP) file in Python 3 while keeping memory usage bounded?
Open sample-webp-10kb.webp in binary mode ('rb'), verify the leading signature (52 49 46 46 ?? ?? ?? ?? 57 45 42 50), and parse sample-webp-10kb.webp (10,240 bytes, SHA-256 feb06afc48077314…) using Pillow for next-gen CMS media libraries.
26. How do I read and validate a .xlsx (XLSX) file in Python 3 while keeping memory usage bounded?
Open sample-xlsx-10kb.xlsx in binary mode ('rb'), verify the leading signature (50 4B 03 04), and parse sample-xlsx-10kb.xlsx (10,240 bytes, SHA-256 93a7146f1632eccd…) using Apache POI XSSF for multi-sheet report generators.
27. How do I read and validate a .xml (XML) file in Python 3 while keeping memory usage bounded?
Open sample-xml-1kb.xml in binary mode ('rb'), verify the leading signature (3C 3F 78 6D 6C), and parse sample-xml-1kb.xml (1,024 bytes, SHA-256 60cac50ebd718050…) using and browser DOMParser for banking ISO 20022 feeds.
28. How do I read and validate a .yaml (YAML) file in Python 3 while keeping memory usage bounded?
Open sample-yaml-1kb.yaml in binary mode ('rb'), verify the leading signature (UTF-8 text), and parse sample-yaml-1kb.yaml (1,024 bytes, SHA-256 f3513b2adbffa831…) using js-yaml for Kubernetes manifests.
29. How do I read and validate a .zip (ZIP) file in Python 3 while keeping memory usage bounded?
Open sample-zip-1kb.zip in binary mode ('rb'), verify the leading signature (50 4B 03 04), and parse sample-zip-1kb.zip (1,024 bytes, SHA-256 d93f32774a20ef7e…) using and fflate for software release packaging.

Part 3: Architecture, implementation and pipeline questions

1. How do I compute the SHA-256 hash of a large .avro file in Python 3.11+ without reading the whole file into memory?
Open the .avro file with open('sample-avro-100mb.avro', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
2. How do I compute the SHA-256 hash of a large .bin file in Python 3.11+ without reading the whole file into memory?
Open the .bin file with open('sample-bin-100mb.bin', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
3. How do I compute the SHA-256 hash of a large .bmp file in Python 3.11+ without reading the whole file into memory?
Open the .bmp file with open('sample-bmp-100mb.bmp', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
4. How do I compute the SHA-256 hash of a large .css file in Python 3.11+ without reading the whole file into memory?
Open the .css file with open('sample-css-100mb.css', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
5. How do I compute the SHA-256 hash of a large .csv file in Python 3.11+ without reading the whole file into memory?
Open the .csv file with open('sample-csv-100mb.csv', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
6. How do I compute the SHA-256 hash of a large .docx file in Python 3.11+ without reading the whole file into memory?
Open the .docx file with open('sample-docx-100mb.docx', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
7. How do I compute the SHA-256 hash of a large .eml file in Python 3.11+ without reading the whole file into memory?
Open the .eml file with open('sample-eml-100mb.eml', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
8. How do I compute the SHA-256 hash of a large .epub file in Python 3.11+ without reading the whole file into memory?
Open the .epub file with open('sample-epub-100mb.epub', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
9. How do I compute the SHA-256 hash of a large .flac file in Python 3.11+ without reading the whole file into memory?
Open the .flac file with open('sample-flac-100mb.flac', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
10. How do I compute the SHA-256 hash of a large .geojson file in Python 3.11+ without reading the whole file into memory?
Open the .geojson file with open('sample-geojson-100mb.geojson', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
11. How do I compute the SHA-256 hash of a large .gif file in Python 3.11+ without reading the whole file into memory?
Open the .gif file with open('sample-gif-100mb.gif', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
12. How do I compute the SHA-256 hash of a large .gltf file in Python 3.11+ without reading the whole file into memory?
Open the .gltf file with open('sample-gltf-100mb.gltf', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
13. How do I compute the SHA-256 hash of a large .gpx file in Python 3.11+ without reading the whole file into memory?
Open the .gpx file with open('sample-gpx-100mb.gpx', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
14. How do I compute the SHA-256 hash of a large .gz file in Python 3.11+ without reading the whole file into memory?
Open the .gz file with open('sample-gz-100mb.gz', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
15. How do I compute the SHA-256 hash of a large .html file in Python 3.11+ without reading the whole file into memory?
Open the .html file with open('sample-html-100mb.html', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
16. How do I compute the SHA-256 hash of a large .ico file in Python 3.11+ without reading the whole file into memory?
Open the .ico file with open('sample-ico-100mb.ico', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
17. How do I compute the SHA-256 hash of a large .ics file in Python 3.11+ without reading the whole file into memory?
Open the .ics file with open('sample-ics-100mb.ics', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
18. How do I compute the SHA-256 hash of a large .ini file in Python 3.11+ without reading the whole file into memory?
Open the .ini file with open('sample-ini-100mb.ini', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
19. How do I compute the SHA-256 hash of a large .jpg file in Python 3.11+ without reading the whole file into memory?
Open the .jpg file with open('sample-jpg-100mb.jpg', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
20. How do I compute the SHA-256 hash of a large .js file in Python 3.11+ without reading the whole file into memory?
Open the .js file with open('sample-js-100mb.js', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
21. How do I compute the SHA-256 hash of a large .json file in Python 3.11+ without reading the whole file into memory?
Open the .json file with open('sample-json-100mb.json', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
22. How do I compute the SHA-256 hash of a large .jsonl file in Python 3.11+ without reading the whole file into memory?
Open the .jsonl file with open('sample-jsonl-100mb.jsonl', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.
23. How do I compute the SHA-256 hash of a large .kml file in Python 3.11+ without reading the whole file into memory?
Open the .kml file with open('sample-kml-100mb.kml', 'rb') and call hashlib.file_digest(f, 'sha256').hexdigest(), which streams the file in C buffer chunks.

Part 4: Verification, edge cases and automation questions

1. Why does opening a binary .avro file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .avro bytes or corrupts byte offsets at byte offset 757.
2. Why does opening a binary .bin file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .bin bytes or corrupts byte offsets at byte offset 1.
3. Why does opening a binary .bmp file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .bmp bytes or corrupts byte offsets at byte offset 58.
4. Why does opening a binary .css file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .css bytes or corrupts byte offsets at byte offset 220.
5. Why does opening a binary .csv file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .csv bytes or corrupts byte offsets at byte offset 201.
6. Why does opening a binary .docx file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .docx bytes or corrupts byte offsets at byte offset 37888.
7. Why does opening a binary .eml file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .eml bytes or corrupts byte offsets at byte offset 420.
8. Why does opening a binary .epub file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .epub bytes or corrupts byte offsets at byte offset 3072.
9. Why does opening a binary .flac file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .flac bytes or corrupts byte offsets at byte offset 185.
10. Why does opening a binary .geojson file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .geojson bytes or corrupts byte offsets at byte offset 120.
11. Why does opening a binary .gif file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .gif bytes or corrupts byte offsets at byte offset 874.
12. Why does opening a binary .gltf file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .gltf bytes or corrupts byte offsets at byte offset 1024.
13. Why does opening a binary .gpx file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .gpx bytes or corrupts byte offsets at byte offset 700.
14. Why does opening a binary .gz file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .gz bytes or corrupts byte offsets at byte offset 35.
15. Why does opening a binary .html file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .html bytes or corrupts byte offsets at byte offset 700.
16. Why does opening a binary .ico file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .ico bytes or corrupts byte offsets at byte offset 1024.
17. Why does opening a binary .ics file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .ics bytes or corrupts byte offsets at byte offset 220.
18. Why does opening a binary .ini file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .ini bytes or corrupts byte offsets at byte offset 120.
19. Why does opening a binary .jpg file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .jpg bytes or corrupts byte offsets at byte offset 632.
20. Why does opening a binary .js file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .js bytes or corrupts byte offsets at byte offset 700.
21. Why does opening a binary .json file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .json bytes or corrupts byte offsets at byte offset 136.
22. Why does opening a binary .jsonl file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .jsonl bytes or corrupts byte offsets at byte offset 37.
23. Why does opening a binary .kml file with open(path, 'r') instead of open(path, 'rb') fail in Python?
Text mode ('r') wraps the file in io.TextIOWrapper using the locale encoding and translates \r\n line endings, which either raises UnicodeDecodeError on binary .kml bytes or corrupts byte offsets at byte offset 400.

Explore all 40 topic-based technical format references

Browse the complete engineering reference library on Testing guides or Frequently asked questions.