Deleting objects
Mark McEahern
mark at mceahern.com
Wed Jan 14 23:01:46 EST 2004
On Wed, 2004-01-14 at 17:23, user at domain.invalid wrote:
> Say I have an object (foo), that contains an
> array (bar) of references to other objects.
>
> Now I want to puff some of the objects from the
> array so that I remove the array element, and
> destroy the oject.
> but when I do:
>
> del foo.bar[0]
>
> Python says:
> object doesn't support item deletion
It'd be helpful if you supplied the code in question. Then again, we
wouldn't be able to let our imagination wander with what puff might
mean. <wink>
Anyway, is this the sort of thing you're talking about?
#!/usr/bin/env python
class Foo:
def __init__(self):
self.bar = []
def __str__(self):
return '<Foo><bar>%s</bar></Foo>' % (str(self.bar),)
l = range(10)
foo = Foo()
foo.bar.append(l)
del foo.bar[0]
print 'foo = %s' % (str(foo),)
print 'l = %s' % (l,)
Cheers,
// m
More information about the Python-list
mailing list