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 trialAlexander Vishnyakov
8,620 PointsWhy this code doesn't pass?
I tested it and it creates new directory in y-m-d format.
import os
def create_daily_dir(date):
formatted_date = format_date(date)
os.mkdir(formatted_date)
def format_date(date):
split_date = date.split("-")
if len(split_date[0]) > 2:
return date
else:
return split_date[2] + "-" + split_date[0] + "-" + split_date[1]
3 Answers
Stuart Wright
41,120 PointsYou need to create the new directory inside the 'financial' sub-directory of your current directory. There are a number of ways you could make this change, but one option is to edit the first line of your create_daily_dir function:
formatted_date = 'financial/' + format_date(date)
Alexander Vishnyakov
8,620 PointsThanks a lot. It did help!
CHRISTOPHER HECKER
1,865 PointsMore notes if anyone is looking to improve the code checker. Seems the code checker doesn't like the os.path.join solutions.
This didn't work: def create_daily_dir(dateStr):
from dateutil.parser import parse
dateStrO = parse(dateStr)
dateStr = dateStrO.strftime('%Y-%m-%d')
os.mkdirs(os.path.join('financial', dateStr), exist_ok = True)
return
This didn't work: def create_daily_dir(dateStr):
from dateutil.parser import parse
dateStrO = parse(dateStr)
dateStr = dateStrO.strftime('%Y-%m-%d')
os.mkdir(os.path.join('financial', dateStr))
return
This worked: def create_daily_dir(dateStr):
from dateutil.parser import parse
import os
dateStrO = parse(dateStr)
dateStr = dateStrO.strftime('%Y-%m-%d')
os.mkdir('financial/' + dateStr),
return