Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7961601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:05:19+00:00 2026-06-04T05:05:19+00:00

import pickle class TasksError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value)

  • 0
import pickle

class TasksError(Exception):
    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)

class Task(object):
    def __init__(self, task = () ):
        if task ==():
            raise TasksError('Empty task.')
        self.name = task[0]
        self.date = task[1]
        self.priority = task[2]
        self.time = task[3]
        self.type = task[4]
        self.comment = task[5]

    def __str__(self):
        output = '''Name: %s
Date: %s
Priority: %s
Time: %s
Type: %s
Comment: %s
''' % ( self.name,
        self.date,
        self.priority,
        self.time,
        self.type,
        self.comment)
        return output

class Tasks(object):
    def __init__(self, container = []):
        self.container = [ Task(todo) for todo in container ]




    def delete(self):

        x = 0
        for todo in self.container:

             x = x + 1
             print "Task Number",x,"\n", todo
             delete = raw_input("what number task would you like to delete")
             if delete == "y":
                 del todo


        ############
        #x = 0
       # for task in self.container:
           # x = x+1
           #print "Task Number",x,"\n", task
            #delete = raw_input("what number task would you like to delete")
            #if delete == "y":
                #del(task)







    def add(self, task):
        if task == '':
            raise TasksError('Empty task')
        self.container.append( Task(task) )






    def __str__(self):
        output = '\n'.join( [ str(todo) for todo in self.container ] )
        return output

if __name__== "__main__":
    divider = '-' * 30 + '\n'



    tasks = Tasks( container = [] ) # creates a new, empty task list

    while True:
        print divider, '''Make your selection:
1. Add new task
2. Print all tasks
3. Save tasks
4. Load tasks from disk
5. Find high priority tasks
6. Sort by date
7. Delete task

<ENTER> to quit
'''
        try:
            menu_choice = int(input("Select a number from the menu: "))
        except:
            print 'Goodbye!'
            break

        if menu_choice == 1:

            task = raw_input (">>> Task: ")
            date = raw_input (">>> Date as string YYYYMMDD: ")
            priority = raw_input (">>> Priority: ")
            time = raw_input (">>> Time: ")
            Type = raw_input (">>> Type Of Task: ")
            comment = raw_input (">>> Any Comments? ")
            todo = (task, date, priority, time, Type, comment)

            tasks.add( todo )
            print tasks
        elif menu_choice == 2:
            print divider, 'Printing all tasks'
            print tasks
        elif menu_choice == 3:
            print divider, 'Saving all tasks'
            tasks.save()
        elif menu_choice == 4:
            print divider, 'Loading tasks from disk'
            tasks.load()
        elif menu_choice == 5:
            print divider, 'Finding tasks by priority'
            results = tasks.find_by_priority(priority='high')
            for result in results: print result
        elif menu_choice == 6:
            print divider, 'Sorting by date'
            tasks.sort_by_date()
            print tasks
        elif menu_choice == 7:

            tasks.delete()

I have deleted parts of my code (hopefully nothing important).
Im having trouble getting python to delete my tasks once added.
Both methods defined as “def delete” give the error message type error: task/todo object does not support deletion.
Does anyone know a way around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:05:20+00:00Added an answer on June 4, 2026 at 5:05 am

    You don’t delete from list like that… Your code have 2 problems:

    • if you use for to loop through a iterable, you should not change it inside the loop.
    • to del from list you should use index.

    Try this:

    index = 0
    while index < len(self.container):
        delete = raw_input("what number task would you like to delete")
        if delete == "y":
            del self.container[index]
        else:
            index += 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my code(i was unable to use 'pickle'): class A(object): def __getstate__(self): print 'www' return
import wx class MainFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self, parent, title=title, size=(640,480)) self.mainPanel=DoubleBufferTest(self,-1) self.Show(True) class DoubleBufferTest(wx.Panel):
import java.lang.reflect.Array; public class PrimitiveArrayGeneric { static <T> T[] genericArrayNewInstance(Class<T> componentType) { return (T[])
import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it,
What is a correct way to pickle an object from a class with slots,
i have the following code in a module called code_database.py class Entry(): def enter_data(self):
Hello I´m trying using the next piece of code: import pickle object = Object()
import org.apache.tools.ant.Project object HelloWorld { def main(args: Array[String]) { println(Hello, world!) } } I
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateDemo { public static void main(String[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.