This module focuses on file handling in Python, covering different file operations, modes, file positioning, and string formatting techniques.
- Solution
- Description:
Task "Product Inventory":
- Implement two classes,
ProductandShop. TheProductclass represents a product with attributes such as name, weight, and category. TheShopclass manages the inventory by reading from and writing to a file, preventing duplicate entries.
- Implement two classes,
- Solution
- Description:
Task "Write and Remember":
- Implement a function
custom_writethat writes a list of strings to a file and returns a dictionary mapping the line number and byte position of each string.
- Implement a function
- Solution
- Description:
Task "Find It Everywhere":
- Implement a
WordsFinderclass 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.
- Implement a
- 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.
- Write code that formats strings using different formatting methods:
- Solution
- Description:
Task "File Operations in the OS":
- Use
os.walkto traverse directories,os.path.jointo construct file paths, and methods such asos.path.getmtime,os.path.getsize, andos.path.dirnameto retrieve file modification times, sizes, and parent directories.
- Use