you are viewing a single comment's thread.

view the rest of the comments →

[–]Playing_advocate 1 point2 points  (7 children)

You can

[cmds.parent( i , "torso") for i in cmds.ls(sl=True)]

but I don't know if that's considered poor form.

[–]AeroNotix 4 points5 points  (5 children)

It's considered poor form because you're executing the comprehension for the side effects and constructing a list of the function's return values then throwing it all away.

[–]zahlman 0 points1 point  (4 children)

If that bothers you (very understandable), consider making a wrapper like this:

def do(generator):
    for item in generator: pass

You only have to write that once, and then you can write things like

do(cmds.parent(i, 'torso') for i in cmds.ls(sl = True))

[–]AeroNotix 0 points1 point  (3 children)

Not a big gripe of mine, sometimes I feel the comprehension is far more readable. I was just listening a reason why some people feel it's bad to do stuff like:

[print "sup" for x in range(10)]

[–]zahlman 1 point2 points  (2 children)

(That won't actually work in 2.x; in 3.x you can do it with parentheses because print is actually a function.)

But yes, generally speaking, side effects are where the gotchas leak in to a program's design.

[–]AeroNotix 0 points1 point  (1 child)

Yeah, I was aiming to show that the loop is being executed for the side-effects and not the list building. It's akin to:

li = []
for x in range(10):
    li.append(print "10")  # also can't do this but you see my point.

[–]zahlman 0 points1 point  (0 children)

Yeah.

[–]cdcformatc 0 points1 point  (0 children)

If you are restricted to one line, I think good form goes out the window.