[Tutor] Acting on objects in a list - how to make the change
kabads at gmail.com
Wed Sep 29 22:08:31 CEST 2004
On Tue, 28 Sep 2004 05:51:17 -0400, Kent Johnson
<kent_johnson at skillsoft.com> wrote:
> You don't need to recreate the hierarchy of lists in your list of things to
> delete. When you create the list of things to delete, you must save a
> reference to the _containing_ list. Look at what is in the tuples in my
> example below - it is the item to delete, and the list to delete it from.
> Take another look at my original answer to your question as well, it shows
> the same thing another way.
Thanks for this - I've gone underground since your last email and have
managed to partly get my head around this to produce some code which
works in deleting an object. However, it doesn't currently delete the
correct object in the list. I'm finding it pass the instance location
of the object. Passing the list itself now works, but currently the
code always deletes the same item position which isn't effective.
Currently the code  drills right down to the article level, with no
other option, so the level code is really not important. The
returned_list holds the list to delete from in  and the item to
delete in . However, how do I pass the location of the actual item,
rather than the object itself? If I pass the object itself, it
correctly throws an error up as only allowing to del with an integer.
Is there a built in function for returning the position of an item?
Once again, thanks for all the help.
def return_a_list(self, level):
if level == 0:
level = raw_input("What would you like to search for? a - article /
i - issue / t - title ")
if level == "t" or level == "i" or level == "a": # Only doing a at the moment
print " I got this far"
chosen_title_object = self.choosetitle()
chosen_issue_object = self.chooseissue(chosen_title_object)
chosen_article_object = self.choosearticle(chosen_issue_object)
returned_list = [chosen_issue_object.articlesheld, chosen_article_object]
# New attempt to try this one now
level = 0
print " I got to choose_what_to_edit"
returned_list = self.return_a_list("a")
confirm = raw_input("Do you wish to delete this article? (y/n)")
if confirm == "y":
print "will be deleted"
for list, item in returned_list:
del list # OK this is deleting, but always the first item
print " will not be deleted "
More information about the Tutor