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

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()