Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python for File Systems Project Starter Solid Paths

Problem with get_root(). Help would be appreciated.

It says:

Bummer! ValueError: 'examples' does not start with '/workdir'

I don't understand what's wrong... What is "examples"?

Help appreciated! :zap: ~Alex

builder.py
import pathlib
import os

def get_root():
    root = pathlib.PurePath(
        input("What's the full path where you'd like the project? ")
    )

    cwd = pathlib.PurePath(os.getcwd())

    if root.relative_to(cwd):
        return cwd.joinpath(root)

    if root.is_absolute():
        return root

    return get_root()

Tagging Chris Freeman + Steven Parker for help

Steven Parker
Steven Parker
229,744 Points

:bell: I was alerted by your tag, but I'll have to leave this one to someone else as I haven't done this course yet myself!

Thanks anyway :)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Your two return values are correct. It is the flow logic that fails the challenge.

The PurePath.relative_to() seems to only work when the comparison is between paths where one is contained in the other.

A simple reorganization of checking if root.is_absolute() works followed by a simple else with your other return value cwd.joinpath(root)

On coding style: I would also suggest that since it is not known if the input path is actually an absolution path, using the variable name root seems confusing. I would suggest using "path" or "project_path". This makes joining cwd with project_path clearer.

Post back if you need more help. Good luck!

Thanks :)