0
0
Pythonprogramming~30 mins

Working with operating system paths in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with operating system paths
📖 Scenario: Imagine you are organizing files on your computer. You want to work with file paths to check where files are stored and create new paths easily.
🎯 Goal: You will create a program that uses Python's os.path module to join folder names and filenames into full paths, and then display the full paths.
📋 What You'll Learn
Use the os.path module
Create variables for folder names and filenames
Join folder names and filenames into full paths
Print the full paths
💡 Why This Matters
🌍 Real World
Working with file paths is important when you organize files, read or save data, and manage folders on your computer.
💼 Career
Many programming jobs require handling file paths to work with files, such as in data analysis, web development, and automation.
Progress0 / 4 steps
1
Create folder and file name variables
Create a variable called folder and set it to the string 'Documents'. Then create a variable called filename and set it to the string 'notes.txt'.
Python
Need a hint?

Use simple assignment like folder = 'Documents'.

2
Import os.path and create a full path variable
Import the os.path module. Then create a variable called full_path that joins folder and filename using os.path.join().
Python
Need a hint?

Use import os.path and then os.path.join(folder, filename).

3
Create another file path with a subfolder
Create a variable called subfolder and set it to the string 'Work'. Then create a variable called work_file that joins folder, subfolder, and filename using os.path.join().
Python
Need a hint?

Use subfolder = 'Work' and join three parts with os.path.join().

4
Print the full paths
Print the variables full_path and work_file each on its own line using two print() statements.
Python
Need a hint?

Use print(full_path) and print(work_file) to show the paths.