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

EOFError: EOF when reading a line

Not sure what is wrong. Tested this in vs.code: All possible inputs return an absolute path from root. Confirming that the path from root to relative are correct. Also if input was not an absolute path it will do get_root() again.

builder.py
import pathlib
import os

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

    test = pathlib.PurePath(root)
    pwd = os.getcwd()
    if f'{pwd}' == f'{root}' or test.is_relative_to(pwd):
        return root
    elif f'{pwd}' != f'{root}': 
        return os.path.abspath(f'{os.getcwd()}{root}')

3 Answers

Steven Parker
Steven Parker
231,236 Points

Remember when testing in an external IDE, it can only confirm the absence of syntax errors but cannot detect if the objectives are being met.

In this case, the instructions say "The function should always return an absolute path", which implies that the function should no longer call itself or ask for input a 2nd time.

I'll try to figure out "always return an absolute path". I'll keep you posted.

Steven Parker
Steven Parker
231,236 Points

As the instructions also say, "if the path is relative, change it into an absolute path".

Steven Parker
Steven Parker
231,236 Points

When the test if not root.is_absolute is not true, the path is absolute and should be returned without modification. But the revised code is still making other tests and may modify the path or possibly not return anything at all.

Well after you mentioned "possibly not return anything at all", I noticed that if someone inputs nothing, I'll get a '.' which I'd fixed later. But, It wasn't enough to pass the problem. I had to step back and rethink my code. Turns out it was silly simple and the code challenge didn't care if the path was from root or not. The cause of my troubles was the wording of get_root(). I made all these 'if' statements to try and catch if the path will come from actual root and make sure to return a path that is true from root to the given input. Lots of unnecessary headaches.

Thanks again for the help!!!

Ok, I'm still having trouble. I get "Got a changed absolute path from an absolute path".
I input the following:

/Users/shawn/teamtreehouse <--- True absolute from root.

Users/shawn/teamtreehouse <--- not absolute, missing '/'

/something/something <-- relative but comes out absolute

something/something <-- bad relative but comes out absolute

All comes out as current working directory path with relative path or just the current directory path.

import pathlib
import os

def get_root():
    pwd = os.getcwd()
    root = pathlib.PurePath(
        input("What's the full path where you'd like the project? ")
    )
    if not root.is_absolute():
        if f'{pwd}' == f'/{root}':
            return f'/{root}'
        else:
            return f'{pwd}/{root}'
    if f'{pwd}' == f'{root}':
        return f'{root}'
    if f'{pwd}' != f'{root}': 
        return f'{pwd}{root}'
Steven Parker
Steven Parker
231,236 Points

Remember the instructions also say "You can assume that the path is relative from the current working directory." So if anything is entered that is not absolute, consider it relative to the current directory and then convert that into absolute.

I have from the input test examples I have shown.