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.

Python Python for File Systems Project Starter Feeling Sluggish

function should accept two arguments, a string to make into an acceptable file or directory name, and a path.

Need help .

slug.py
import os
import pathlib
import re
import sys

FILES = {
    '{PROJECT_SLUG}/REQUIRMENTS.TXT': 'requirements.txt.template',
    '{project_slug}/app.py': "app.py.template',
    '{project_slug}/static/css/{project_slug.css}': 'project.css.template',
    '{project_slug}/static/js/{project_slug}.js': 'project.js.template',
    '{project_slug}/templates/index.html': 'index.html.template'
}

def slugify(string, path):
    string = unicodedata.normalize('NFKC', string)
    string = re.sub(r'[^\w\s]', '',string).strip().lower()
    return re.sub(r'[_\-\s|+', '_', string)

def create_files(root, slug, name):       
    for file_name, template_name in FILES.items():
        try:
            template_file = open(os.path.join('templates', template_name))
            file_content = template_file.name()
            file_conten = flask_template_prepare(file_content)
            file_content = file_content.format(project_name=name, project_slug=slug)
            file_content = flask_template_repair(file_content)


            target_file = open(os.path.join(root, file_name.format(project_slug)), 'w')
            target_file.write(file_content)
        except OSError: 
            print("couldn't create {}".format(file_name.format(project_slug=slug)))
        finally:
            template_file.close()
            target_file.close()


def main():
    project_root = get_root()
    check_delete_root(project_root)
    project_name = None
    while not project_name:
        project_name = input("What's the full name for the project? ").strip()
    project_slug = slugify(project_name)

    create_dirs(project_root, project_slug)
    print("Creating {} in {}".format(project_name, project_root))


    if __name__ == '__main__':
        main()