Recall & Review
beginner
What is the purpose of the
os.path module in Python?The
os.path module helps manage and manipulate file paths in a way that works across different operating systems.Click to reveal answer
beginner
How do you join directory names and filenames into a full path safely?
Use
os.path.join() to combine parts of a path. It adds the right separators for your operating system.Click to reveal answer
beginner
What does
os.path.exists(path) check?It checks if the file or directory at
path actually exists on your computer.Click to reveal answer
intermediate
Explain the difference between
os.path.abspath() and os.path.relpath().os.path.abspath() gives the full absolute path from the root, while os.path.relpath() gives the path relative to another directory.Click to reveal answer
intermediate
What is the modern recommended way to handle file paths in Python 3.4+?
Use the
pathlib module, which provides an easy and clear object-oriented way to work with file paths.Click to reveal answer
Which function joins parts of a file path correctly across operating systems?
✗ Incorrect
os.path.join() safely combines path parts using the right separator for the OS.
What does os.path.exists('file.txt') return if 'file.txt' is not found?
✗ Incorrect
os.path.exists() returns False if the file or directory does not exist.
Which module provides an object-oriented way to handle file paths?
✗ Incorrect
pathlib offers classes to work with paths in a clear and modern way.
What does os.path.abspath('file.txt') return?
✗ Incorrect
os.path.abspath() returns the full absolute path from the root to the file.
Which function splits a path into directory and filename?
✗ Incorrect
os.path.split() separates a path into the directory part and the filename.
Describe how to safely combine folder names and filenames into a full path in Python.
Think about how to avoid errors with slashes on Windows vs Linux.
You got /3 concepts.
Explain the benefits of using pathlib over os.path for file path handling.
Consider how pathlib uses objects instead of strings.
You got /4 concepts.