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 trialWilliam Hall
19,502 Pointsi have no clue how to do this
I'd like you to change how get_root works. I still want to ask for a path but if the path is relative, change it into an absolute path. You can assume that the path is relative from the current working directory. The function should always return an absolute path.
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()
return root
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsHey William Hall, let's break it down.
The starter code keeps recursively calling the defined function get_root
if the path is not absolute. Since the task is to return an absolute path if an non-absolution path is input, replacing the recursive call with an absolute path created from the non-absolution path input should work. The form would be:
if not root.is_absolute():
return <absolution path created from root variable>
return root
One way to get an absolution path is to prepend current working directory to the relative path to get an absolution one. Looking at the documentation for Path.cwd(), this method gives the path to the current working directory.
Looking at the documentation for PurePath(), a pure path can be created from path segments. Using PurePath()
with the cwd and root segments should create the full absolution path ready for return.
Post back if you need more help. Good luck!!
William Hall
19,502 PointsWilliam Hall
19,502 Pointssorry, but this is not "laymen" enough for me to grasp from your answer unfortunately. Thanks for responding though.
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 Pointswhat part needs more detail?
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsWilliam Hall Did you get this solved? what what the issues?