I'm trying to send a command through a port to another program. In the second program I want to see if a light exists, and if so, set up a new variable which is equal to that light. Over three lines of code it looks like this...
for light in mari.lights.list():
if light.isEnvironmentLight():
myEnvLight = light
Then, I'll be able to set some attributes for 'myEnvLight' over some additional socket commands... The trouble I'm having is in sending a for and if statement through as a single line command.
I've tried using 'list comprehension' to cut down the 'for' part of the code, and then I'm trying to use a ternary operator to simplify the 'if' part. Both of these things are new to me. The result I have so far is
myEnvLight = [light if light.isEnvironmentLight() else 0 for light in mari.lights.list()]
Now this probably strikes most of you as a bunch of nonsense, but it's the best I've got so far! So, just wondering if anyone has a way of fitting those three lines down to one line?