Doubt regarding the Python syntax

Asked

Viewed 54 times

1

Good evening guys, my question is about a piece of code I found in a book about Python and Opencv. The author created the function that I will put below:

@property
def frame(self):
    if self._enteredFrame and self._frame is None:
        _, self._frame =  self._capture.retrieve()
    return self._frame

My question is about the line: _, self. _frame = self. _capture.Retrieve(). Because it has an underline and a comma before self. _frame = ... ?

  • Um, I still can’t figure out the syntax by reading this article. But thanks for the answer.

1 answer

2


This is an unstructurer. self. _capture.Retrieve() returns a tuple with 2 elements, let’s assume 'apple' and 'orange' With the following syntax:

frutas = ('maçã', 'laranja')

You would have a tuple with apple at position 0, and orange at position 1, but you can also take the values this way:

fruta1, fruta2 = ('maçã', 'laranja')

In this case fruit 1 will have apple, and fruit 2 will have orange.

If you do not want to use the first value returned, it is recommended that you use an _ to capture that value, as is the case with your code, i.e., _ contains the first value of the tuple, which is irrelevant, and self. _frame contains the second value of the tuple.

  • Ah ta, got it, thank you very much!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.