Skip to content

Latest commit

 

History

History
43 lines (37 loc) · 2.01 KB

MODULE_7.md

File metadata and controls

43 lines (37 loc) · 2.01 KB

Module 7: Working with Files and Formatted Output

Module Description

This module focuses on file handling in Python, covering different file operations, modes, file positioning, and string formatting techniques.

Assignment 1: Homework on "File Opening Modes"

  • Solution
  • Description: Task "Product Inventory":
    • Implement two classes, Product and Shop. The Product class represents a product with attributes such as name, weight, and category. The Shop class manages the inventory by reading from and writing to a file, preventing duplicate entries.

Assignment 2: Homework on "File Positioning"

  • Solution
  • Description: Task "Write and Remember":
    • Implement a function custom_write that writes a list of strings to a file and returns a dictionary mapping the line number and byte position of each string.

Assignment 3: Homework on "With Statement"

  • Solution
  • Description: Task "Find It Everywhere":
    • Implement a WordsFinder class that takes a list of file names and provides methods to get all words from the files, find the first occurrence of a word, and count the number of occurrences of a word across all files.

Assignment 4: Homework on "String Formatting"

  • Solution
  • Description: Task "String Formatting":
    • Write code that formats strings using different formatting methods: %, .format(), and f-strings, for various scenarios involving team statistics, competition results, and task completion times.

Assignment 5: Homework on "File System Operations"

  • Solution
  • Description: Task "File Operations in the OS":
    • Use os.walk to traverse directories, os.path.join to construct file paths, and methods such as os.path.getmtime, os.path.getsize, and os.path.dirname to retrieve file modification times, sizes, and parent directories.