Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GIF frames deleting script.
#7
(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.
Reply


Messages In This Thread
GIF frames deleting script. - by rey - 04-02-2023, 12:29 PM
RE: GIF frames deleting script. - by rey - 04-03-2023, 10:05 AM
RE: GIF frames deleting script. - by Ofnuts - 04-03-2023, 02:41 PM
RE: GIF frames deleting script. - by rey - 04-03-2023, 05:18 PM
RE: GIF frames deleting script. - by Ofnuts - 04-03-2023, 09:23 PM
RE: GIF frames deleting script. - by teapot - 04-04-2023, 03:30 AM
RE: GIF frames deleting script. - by Ofnuts - 04-04-2023, 07:26 AM
RE: GIF frames deleting script. - by teapot - 04-05-2023, 02:21 AM

Forum Jump: