[Tutor] Append a dictionary value
David
david at abbottdavid.com
Sat Apr 4 23:17:56 CEST 2009
I put together a todo program here;
http://linuxcrazy.pastebin.com/f74beaf78
And I am trying to add an option to edit the values which are date and
time. Below I have gotten this far but now I need some help. looks like
my attempt to use setdefault will not work. Please point me in the right
direction my head has started to hurt :)
thanks
-david
#!/usr/bin/python
import time
import datetime
todo = {'Study Python':
(datetime.date(2009, 4, 1), datetime.time(12, 15)),
'Clean House':
(datetime.date(2009, 4, 4), datetime.time(15, 15)),
'Fix Python Code':
(datetime.date(2009, 3, 29), datetime.time(9, 1))}
for k, v in todo.iteritems():
print k, v[0],v[1]
answer = raw_input('\nWhich Todo do you want to edit? \nEnter >> ')
for k, v in todo.iteritems():
key = todo[answer]
current_date = key[0]
print 'Current Date and Time for', answer,'\n'
print 'Date: =', current_date
current_time = key[1]
print 'Time: =', current_time
print """
Enter D: Edit Date
Enter T: Edit Time
"""
new_value = raw_input('\nWhich value do you want to edit? ')
new_value = new_value.lower()
if new_value == 'd':
print 'Next, enter date for Todo: '
curr_date = time.strftime('%Y %m %d', time.gmtime())
print 'Format as ', curr_date
yr = int(raw_input('\nEnter Year: '))
mt = int(raw_input('Enter Month: '))
dy = int(raw_input('Enter Day: '))
datevalue = datetime.date(yr, mt, dy)
todo[answer] = datevalue, time
#todo.setdefault(answer,[current_date]).append(datevalue)
elif new_value == 't':
hr = int(raw_input('\nEnter Hour (24h): '))
mn = int(raw_input('Enter Minute (01-59): '))
sec = 0
hourvalue = datetime.time(hr, mn, sec)
todo[answer] = date, hourvalue
#todo.setdefault(answer,[current_time]).append(hourvalue)
else:
print 'big time error'
--
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu
More information about the Tutor
mailing list