Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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)) try: os.makedirs(dir) except: sys.exit()