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

Completely stuck please help

Challenge Task 1 of 1 I made a slugify function in the last video, but that is just one approach to making a slug. I want you to make your own slugify function in slug.py. Your function should accept two arguments, a string to make into an acceptable file or directory name, and a path.

The rules? Slugs should be unique for their path (you can't have two files or directories with the same name in the same directory), slugs shouldn't have spaces in them, and slug should start with a number, letter, or underscore. Other than that, it's up to you!

import os
import re

def slugify(slug, path):
    slug = unicodedata.normalize('NFKC', slug)
    slug = re.sub(r'[^\w\s]', '', slug).strip().lower()
    slug = re.sub(r'[_-\s]+', '_', slug)
    dir = os.path.dirname(os.path.join(path, slug))