I am desperately trying to delete a calendar (task list) by name, using the reminder class and delete_calendar. Also checked the documentation and web with no result. Would you mind providing me a simple code example? Thanks!
Forum Archive
Reminders - Delete Calendar (List)
import reminders
print('=' * 25)
c = reminders.get_all_calendars()[0]
print(c)
r = reminders.Reminder(c)
r.title = 'Take out the garbage'
r.save()
r = reminders.Reminder(c)
r.title = 'Walk the dog'
r.save()
while(True):
r_list = reminders.get_reminders(c)
for i, r in enumerate(r_list):
print(i , r)
i = int(input('Enter number of reminder to delete ("q" to quit): ').strip())
reminders.delete_reminder(r_list[i])
import reminders
print('=' * 25)
c = reminders.Calendar()
c.title = "Delete Me!!!"
c.save()
print(c)
while True:
calendars = reminders.get_all_calendars()
for i, calendar in enumerate(calendars):
print(i, calendar)
i = int(input('Enter number of the calendar to delete ("q" to quit): ').strip())
reminders.delete_calendar(calendars[i])
Hello,
many thanks for your incredible fast reply! I copy-pasted and executed the code and received the following error message:
(...)
line 15, in
reminders.delete_calendar(calendars[i])
TypeError: 'str' object is not callable
(...)
maybe it's a device setting then... kind regards,
Simon
Did you enter a number (3) or a string ("Delete Me!!!")?
Please paste the full text of your run.
Are you on Python 2??
import reminders
try: # https://docs.python.org/3/whatsnew/3.0.html#builtins
raw_input # Python 2
except NameError:
raw_input = input # Python 3
print('=' * 25)
c = reminders.Calendar()
c.title = "Delete Me!!!"
c.save()
print(c)
while True:
calendars = reminders.get_all_calendars()
for i, calendar in enumerate(calendars):
print(i, calendar)
i = int(raw_input('Enter number of the calendar to delete ("q" to quit): ').strip())
reminders.delete_calendar(calendars[i])
Hi, python 3.5 is indicated on the top. With both codes, I get the same error message (see below).
=========================
0
1
2
3
Enter number of reminder to delete ("q" to quit): 1
Traceback (most recent call last):
File „(…)“, line 15, in
reminders.delete_calendar(calendars[i])
TypeError: 'str' object is not callable
Thanks again!
Works fine for me. Your exception suggests that in your enviroment the functiondelete_calendar() in the namespace reminders has been overwritten with a string of the same name. You should investigate that with the inspector when your exception is raised.
Or more likely ... you have missed a parenthesis while copying the snippet which often completely confuses the interpreter.
@simon You could insert these three lines just before the line that is failing.
print('({}): {}'.format(type(i), i))
print('({}): {}'.format(type(calendars[i]), calendars[i]))
print(reminders.delete_calendar)
# you should see results like:
# (<class 'int'>): 4
# (<class 'reminders.Calendar'>): <Calendar "Delete Me!!!">
# <built-in function delete_calendar>
Good Morning Both,
Many thanks for your quick help!!!
I have closed / killed the APP an restarted Pythonista. Now the proposed solution works.
The issue is eventually, as I tried to delete the calendar with a name string instead of a calendar object in the beginning and the wrong solution was cached...