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 trialRafay Ahmed
956 PointsHi, I dont know what I'm doing wrong
Can someone help me out?
import os
def delete_by_date(date):
for f in os.listdir(os.getcwd() + '/backups'):
if date in f:
os.remove('backups/' + f)
def delete_by _user(username):
for username in os.listdir(os.getcwd()):
if username.is_file:
os.remove(username.path)
1 Answer
Trevor J
Python Web Development Techdegree Student 2,107 PointsUnless you are referring to Challenge Task 2 of 2 and not 1
You don't need the delete_by_user()
, remove this method and try again.
Also there should not be a spcae after by
in the method name.
def delete_by _user(username):
for username in os.listdir(os.getcwd()):
if username.is_file:
os.remove(username.path)
For Challenge Task 2 of 2 the delete_by_user
method is the same just change date
for username
def delete_by_date(date):
for f in os.listdir(os.getcwd() + '/backups'):
if date in f:
os.remove('backups/' + f)
def delete_by_user(username):
for f in os.listdir(os.getcwd() + '/backups'):
if username in f:
os.remove('backups/' + f)
Or for a cheeky shortcut:
def delete_by_date(date):
for f in os.listdir(os.getcwd() + '/backups'):
if date in f:
os.remove('backups/' + f)
def delete_by_user(username):
delete_by_date(username)
Rafay Ahmed
956 PointsRafay Ahmed
956 PointsMake a function named delete_by_date. It should take date string like 2015-10-31 and delete any files in the "backups" local directory that have that date in their filename.
Just like the last challenge, the files will be named in the format "year-month-day-username.extension".
This is the question