def check_date(date,num_days): # this function takes a date and number of days and returns the start and end dates
if num_days < 0 or num_days > 31:
print "The argument for -n has to be between 0 and 31"
sys.exit(1)
else:
p = re.compile('\d\d/\d\d/\d\d\d\d')
m = p.match(date)
if m == None:
print "The argument for -D has to be in the format: dd/mm/yyyy"
sys.exit(1)
else:
try:
date_list = m.group().split('/')
date_list.reverse()
startdate = datetime.date(int(date_list[0]),int(date_list[1]),int(date_list[2]))
enddate = startdate + datetime.timedelta(days=num_days)
except ValueError:
#here i want to print the exact error message generated by the Python interpreter (it reduces the error checking from my side, the value error is generated if the User inputs an INVALID DATE)
return (startdate,enddate)
--
To HIM you shall return.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor