LearnPy Hub
← Context Managers problems
Hard

Working in a Folder

Write a context manager in_dir(path) that creates the folder if needed, changes into it with os.chdir, and changes back afterwards. Inside, create the file named on the input with text ok. Print the folder name you were in during the block (basename) and whether the file exists relative to the original folder as FOLDER/FILE.

Input

A folder name, then a file name.

Output

Two lines.

Sample 1

Input
work
note.txt
Output
work
True

Sample 2

Input
data
x.csv
Output
data
True
solution.py
Output appears here
Working in a Folder · Python practice problem · LearnPy Hub