What's the effect of `pass` in Python debug mode
what is called
how to pronounce what
I just found this phenomenon by coincidence.
mylist = [('1',), ('2',), ('3',), ('4',)] for l in mylist: print(l) pass # first pass pass # second pass print("end")
If I set the red stop point at the first
pass and debug, the program will stop here and the output is:
However, if I set the red stop point at the second
pass and debug, the output include the
end in the last line. It seems like the
pass avoid stopping at this point and just let the program run further.
pass should have no real meaning, but it seems not. So how can understand the
Thank you all
pass is just syntactic sugar for the parser to know that a statement is intentionally left empty. It does not generate an opcode, and thus, the debugger can't pause when it gets hit. Instead you're seeing it halt when the next instruction is executed.
You can see this by printing the opcodes generated by an empty function:
>>> def test(): ... pass ... >>> import dis >>> dis.dis(test) 2 0 LOAD_CONST 0 (None) 3 RETURN_VALUE
What, I will do what I can to help you. TranslationsEdit. show ▽what? (interrogative pronoun)� WhatsApp works with Safari 9+ To use WhatsApp, update Safari or use Google Chrome, Mozilla Firefox or Opera.. Update Safari
pass doesn't do anything. It compiles to no bytecode. However, the bytecode to jump back to the start of the loop is associated with the line of the last statement in the loop, and
pass counts. Here's what it looks like if we decompile it, on Python 3.7.3:
import dis dis.dis(r'''mylist = [('1',), ('2',), ('3',), ('4',)] for l in mylist: print(l) pass # first pass pass # second pass print("end")''')
1 0 LOAD_CONST 0 (('1',)) 2 LOAD_CONST 1 (('2',)) 4 LOAD_CONST 2 (('3',)) 6 LOAD_CONST 3 (('4',)) 8 BUILD_LIST 4 10 STORE_NAME 0 (mylist) 2 12 SETUP_LOOP 20 (to 34) 14 LOAD_NAME 0 (mylist) 16 GET_ITER >> 18 FOR_ITER 12 (to 32) 20 STORE_NAME 1 (l) 3 22 LOAD_NAME 2 (print) 24 LOAD_NAME 1 (l) 26 CALL_FUNCTION 1 28 POP_TOP 4 30 JUMP_ABSOLUTE 18 >> 32 POP_BLOCK 6 >> 34 LOAD_NAME 2 (print) 36 LOAD_CONST 4 ('end') 38 CALL_FUNCTION 1 40 POP_TOP 42 LOAD_CONST 5 (None) 44 RETURN_VALUE
POP_BLOCK get associated with line 4, the first
When you set a breakpoint on the first
pass, Python breaks before the
JUMP_ABSOLUTE. When you set a breakpoint on the second
pass, no bytecode is associated with line 5, so Python breaks on line 6, which does have bytecode.
P!nk - So What (Official Music Video), what definition: 1. used to ask for information about people or things: 2. used in questions that show you are…. Learn more. noun the true nature or identity of something, or the sum of its characteristics: a lecture on the whats and hows of crop rotation.
pass is just a null operator, if your looking to exit the for loop, you need to use break. The reason you see the end of the output from mylist at the second pass is that the first pass just continues the for loop.
what, what definition: The definition of what is which one or as many as. (adjective) An example of what used as an adjective is in the sentence, "What shirt do you� what definition: 1. used to ask for information about people or things: 2. used in questions that show you are…. Learn more.
WHAT, Usage Note: When what is the subject of a clause, it takes a singular verb if the word or phrase that completes the sentence (the complement) is singular, as in I � whatever: adverb at all , of any description , of any kind or sort , whatsoever , whichever
What dictionary definition, Before you work yourself into a frenzy, take a moment to assess what's really going on and identify what's causing the strain in your relationship� Desperate to secure funding for her med tech startup, an idealistic scientist and her husband strike an outrageous deal with a mysterious investor. Watch trailers & learn more.
What, “Before you get tested, learn more about COVID-19 testing and what TRICARE covers on TRICARE.mil.” Diagnostic Test. A diagnostic (viral)� WhatsApp Messenger: More than 2 billion people in over 180 countries use WhatsApp to stay in touch with friends and family, anytime and anywhere. WhatsApp is free and offers simple, secure, reliable messaging and calling, available on phones all over the world.
- Did you mean breakpoint by "red stop point"?