Python del() built-in can't be used in assignment?

Posted by emcee on Stack Overflow See other posts from Stack Overflow or by emcee
Published on 2010-05-24T08:12:22Z Indexed on 2010/05/24 8:21 UTC
Read the original article Hit count: 304

Filed under:
|

I noticed a problem when I was trying to use del in a lambda to thin out a list of threads to just those running:

map(lambda x: del(x) if not x.isAlive() else x, self.threads)

Ignore for a second that this doesn't do anything, I'm just fooling around with map, reduce, and lambda.

This fails with a syntax error at del(x). With some messing around, I think the problem is del() doesn't return a value. For example, this fails with the same error:

b = 5
x = del(b)

This doesn't, however:

def rmThis(x): del(x)

Which means I'm using this workaround:

map(lambda x: rmThis(x) if not x.isAlive() else x, self.threads)

So is the limitation just because del() doesn't return a value? Why not?

I'm using python 2.6.2

© Stack Overflow or respective owner

Related posts about python

Related posts about built-in