04-04-2023, 07:26 AM
(04-04-2023, 03:30 AM)teapot Wrote: Hi Ofnuts, I'm confused by this line of your suggested code:
(04-03-2023, 02:41 PM)Ofnuts Wrote:Code:
layers=image.layers[:] # Make a copy of the list
I get that it makes a copy of a list but could it just be:
Code:
layers=image.layers
I thought the ‘layers’ attribute of an image or layer group builds a new Python list and copies into it the IDs of the layers so that gives the plugin it's own private list anyway?
Maybe, and maybe not. The indexation operator [] is just a call to a __getitem__() method, so image.layers could be live-wired into the image layers, retrieving layers on the fly when __getitem__() is called. In other words it's indexable but not necessarily a list. And in that case iterating the collection while deleting stuff in it is not going to be pretty.
Of course, in this particular case, it is a list, so yes, the copy isn't entirely necessary.