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 trialian mays
5,214 PointsI'm not getting the right values for some of the paths and I'm not sure why.
It's unclear to me if I'm writing a function from scratch or if I'm supposed to use some of the functions from the OS module to help the function along.
import os
def absolute(path_string, root_string):
if root_string != "/":
root_string = "/"
if path_string.startswith('/'):
return path_string
if not path_string.startswith('/'):
return root_string + path_string
1 Answer
Kevin Esther
8,551 PointsHi Ian,
The function you have written would pass I think if you make sure that you are returning a string to a new variable.
if you try adding the below code to what you have already written see if this passes.
path_1 = str(absolute("projects/python_basics/", "/"))
path_2 = str(absolute("/home/kenneth/django", "C:\\"))
print(path_1)
print(path_2)
print(type(path_1))
print(type(path_2))
Think the idea was to use the os.path.isabs() method however as with python there are many ways to do one thing.