Hi i’m trying to get objects by name and properties but it doesnt work. Whats wrong with my code?
for obj in objs:
if 'MenuItem' in obj and obj == active_item:
print("It Worked!")
else:
print("F**k s**t!!")
Name of property is ‘MenuItem’ and variable ‘active_item’ is exactly the same as the object name. If i search only for the property name it works. No error in console, btw.
That is indeed better in most cases but not all. In single pulse mode (or for creating that list once) it’s best to do it that way. But if you use it in true pulse, a simple for loop is faster and lighter to use.
The reason behind it is easy, 1 less loop trough all the objects.
objects_list loops trough all objects, then you need another loop to get trough that list, while you can grab it in one single loop.
When you worry about readability place the code into a function with an understandable name. E.g. “filterByNameAndProperty” (or “filter_by_name_and_property”).