omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Reminders - Delete Calendar (List)

    Pythonista
    3
    10
    4191
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • simon
      simon last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by ccc

          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])
          
          1 Reply Last reply Reply Quote 1
          • simon
            simon last edited by

            Hello,
            many thanks for your incredible fast reply! I copy-pasted and executed the code and received the following error message:
            (...)
            line 15, in <module>
            reminders.delete_calendar(calendars[i])
            TypeError: 'str' object is not callable
            (...)

            maybe it's a device setting then... kind regards,

            Simon

            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by

              Did you enter a number (3) or a string ("Delete Me!!!")?

              Please paste the full text of your run.

              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by ccc

                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])
                
                1 Reply Last reply Reply Quote 0
                • simon
                  simon last edited by

                  Hi, python 3.5 is indicated on the top. With both codes, I get the same error message (see below).

                  =========================
                  <Calendar "Delete Me!!!">
                  0 <Calendar "Delete Me!!!">
                  1 <Calendar "Delete Me!!!">
                  2 <Calendar "Delete Me!!!">
                  3 <Calendar "Delete Me!!!">
                  Enter number of reminder to delete ("q" to quit): 1
                  Traceback (most recent call last):
                  File „(…)“, line 15, in <module>
                  reminders.delete_calendar(calendars[i])
                  TypeError: 'str' object is not callable

                  Thanks again!

                  1 Reply Last reply Reply Quote 0
                  • zipit
                    zipit last edited by zipit

                    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.

                    1 Reply Last reply Reply Quote 2
                    • ccc
                      ccc last edited by ccc

                      @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>
                      
                      1 Reply Last reply Reply Quote 0
                      • simon
                        simon last edited by

                        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...

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors