ReviseAlgo Logo

File Handling

9 Topics
1

Opening and Closing Files

open() function, file modes, and proper cleanup

Essential — tests understanding of file I/O, resource management, and the with statement
2

Reading Files

read, readline, readlines, and iteration methods

File input — tests understanding of memory-efficient reading and different reading strategies
3

Writing Files

write, writelines, and file output patterns

File output — tests understanding of write modes, buffering, and efficient output
4

File Modes

Understanding r, w, a, b, x, and + modes

File access — tests understanding of mode combinations and when each is appropriate
5

with Statement for Files

Context managers and the with statement for safe, automatic resource cleanup when working with files and other resources.

Essential best practice — interviewers expect you to use with for file handling and understand the context manager protocol.
6

Binary Files

Reading and writing non-text data (images, audio, serialized objects) using binary mode and the struct module for precise byte-level control.

Tests understanding of bytes vs strings, encoding, and low-level data manipulation — common in systems programming interviews.
7

JSON Files

Comprehensive JSON handling in Python — serialization, deserialization, custom encoders/decoders, working with JSON Lines, and streaming large JSON data.

JSON is the universal data interchange format — interviewers test your ability to parse, generate, and manipulate JSON data efficiently.
8

CSV Files

Comprehensive CSV handling — reader/writer, DictReader/DictWriter, custom dialects, and processing large CSV files efficiently.

CSV processing is common in data engineering and backend interviews — know both basic and DictReader approaches.
9

pathlib Module

Modern, object-oriented filesystem path manipulation — path construction, file operations, directory traversal, and glob patterns using the pathlib module.

pathlib is the modern standard for path handling in Python 3 — interviewers prefer it over os.path for cleaner, cross-platform code.