0
bkg = map(lambda x: x / 255.0, [26, 51, 102, 255])    
colors.SetColor("BkgColor", *bkg)
#This is a class of the VTK library that sets the color properties of an actor

colors.SetColor("BkgColor", *bkg) 

I'm having an issue with iterator references while learning open source code, the main issues are as follows:

First map returns an iterator, then the second SetColor parameter below asks for the color values of the three channels and the range of the three values. It is clear that the above list has preset these four input values.

The first question, what is the way to ask the iterator "*bkg", which is a bit like the way C++ asks the iterator currently pointing to the value?

The second question is, does the iterator of bkg perform a value reference after all 4 values are calculated, or does it perform a value operation when it is necessary to reference bkg? The third question, I am not proficient enough in the use of iterators, is there any way to debug and analyze iterators?

I tried using print or direct breakpoint debugging to see bkg, but it didn't seem to work very well.And after printing, the later setColor cannot be used.

enter image description here

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Dra Hy
  • 1
  • 2
  • An iterator can normally only be iterated one time - which is just fine in this code, as it only *needs* to be iterated one time, but makes it hard to examine what's going on. So change it temporarily to `bkg = list(map(...))` - as a list, you can look at (and even modify) the contents as many times as you want, yet it will still work when passed to `SetColor()`. – jasonharper Jan 18 '23 at 03:48
  • 1
    Does this answer your question? [Why can't I iterate twice over the same iterator? How can I "reset" the iterator or reuse the data?](/questions/25336726) and [What does the star and doublestar operator mean in a function call?](/questions/2921847/) Also: welcome to Stack Overflow. Please note that this is **not a discussion forum**; generally we are looking for **one** question at a time. – Karl Knechtel Jan 18 '23 at 08:29
  • Please [don’t post images of code, error messages, or other textual data.](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) – tripleee Jan 18 '23 at 08:43

1 Answers1

0

I rarely used the method of variable length arguments in my previous studies, so I don't know how to use *bkg. So after reviewing the relevant documentation, I think the above code works like this:

First, after the local function operation of lambda, a series of values of the color channel are obtained, and bkg is an iterator for iterating over the list values processed by lambda above

Then, the SetColor() function can actually receive a different number of arguments (of course, receiving different parameters will have different returns), and the function passes parameters in a variable-length real parameter, that is, *bkg. Therefore, the four values calculated above will be passed into the function as tuples (note that they are converted to tuples, not directly in the form of a list).

If there is still a difference between the above elaboration and the actual operation principle, please point it out under the comment in time

Dra Hy
  • 1
  • 2