Module 7
File Handling and Data Formats
// Lessons
6
// Quiz questions
90
// Reading time
155 min
// Exam length
15 Q
// Coding exercises
10
- 1Text File I/O & Context ManagersOpen, read, write, and append disk files safely using the with statement and automatic resource cleanup. 25 min 15 questions
- 2Filesystem Navigation with PathlibConstruct cross-platform directory paths, inspect file metadata, and pattern-match with glob. 25 min 15 questions
- 3CSV Data Ingestion & ExportParse, filter, and write tabular comma-separated records using csv.reader and csv.DictReader. 25 min 15 questions
- 4JSON Serialization & API PayloadsEncode and decode JSON objects, handle file streams, and convert complex custom types. 25 min 15 questions
- 5Unicode Encodings & Raw Binary FilesManage bytes versus strings, encode UTF-8 text, handle binary byte buffers, and prevent decoding errors. 25 min 15 questions
- 6ETL Pipeline ArchitectureDesign clean data extraction, schema validation, record transformation, and loading pipelines. 30 min 15 questions
Coding practice: write it yourself
Real Python, real checks: write your answer, press Run checks, and keep going until it passes. (4 exercises)
Coding practice needs an account. Sign in or create a free ID to run these exercises.
Lab 1: Path stem extraction
Construct a pathlib.Path("data/reports/q3_earnings.xlsx"). Extract and print its stem and suffix: Stem: q3_earnings, Suffix: .xlsx.
Coding Practice is Locked
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.
Lab 2: CSV salary sum
Parse CSV text "name,pay\nAli,500\nSara,700" using csv.DictReader and io.StringIO. Print: Total payroll: 1200.
Coding Practice is Locked
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.
Lab 3: Serialize JSON
Serialize {"status": "healthy", "uptime": 99.9} to a JSON string with indent=2 and print it.
Coding Practice is Locked
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.
Lab 4: UTF-8 byte length
Encode the string "Python 🐍" to UTF-8 bytes. Print: Byte length: 11.
Coding Practice is Locked
Sign in to access the interactive Python editor, write and run code checks against automated tests, use hints, and earn XP.
References & Further Reading
Related entries from PyLabs's own reference library.