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 Feeling Sluggish

Megan Weber
Megan Weber
31,305 Points

'Bummer: Try again!'?

I don't know what the problem is or what it wants.

slug.py
import os
import pathlib
import re
def slugify(oldstring, path):
    oldstring = oldstring.replace(' ', '')
    if not re.match('\w', oldstring):
        oldstring = '_' + oldstring
    newstring = oldstring
    n = 1
    while os.path.exists(os.path.join(path, newstring)):
        newstring = pathlib.PurePath(oldstring).stem + '#' + n + pathlib.PurePath(oldstring).suffix
        n += 1
    return os.path.join(path, newstring)

1 Answer

Megan Weber
Megan Weber
31,305 Points

Using path in the if statement instead of oldstring fixed it.