One: Generator:generator is a function with the next method,
A function generates an iterator during execution, which is the generator, where the contents of the iterator need to be read using the function __next__ () method, such as:
deffunc (): With open ("haproxy.cfg") as F:Try:#during normal execution. whileTrue:line=next (f)Print(line,end="') exceptStopiteration:#catches to the specified exception thrown Print("has been completed") func () execution Result:GlobalLog127.0.0.1local2 Daemon Maxconn256Log127.0.0.1local2 infodefaults LogGlobalmode HTTP Timeout connect 5000ms timeout client 50000ms timeout server 50000ms opt Ion Dontlognulllisten Stats:8888stats enable stats URI/Admin Stats Auth admin:1234frontend oldboy.org Bind0.0.0.0:80option httplog option httpclose option forwardfor logGlobalACL www hdr_reg (host)-i www.oldboy.org use_backend www.oldboy.orgifwwwbackend www.oldboy.org Server100.1.7.9 100.1.7.9 Weight Maxconn 3000Backend AAA Server100.1.7.9 100.1.7.91 Weight 20maxconn 3000backend test.oldboy.org Server100.1.7.999 100.1.7.999 Weight Maxconn 30Backend test.oldboy.org Server100.1.7.33 100.1.7.33 Weight Maxconn 30Server1.1.1.1 Weight Maxconn 30Server100.1.7.999 100.1.7.999 Weight Maxconn 30The file has been read completed-#after capturing the stopiteration error that was thrown after the next () method was executed without a readable line, the code underneath it was executed
Next ()
The device cannot go backwards in operation, only forward
Python Fourth: Generators and iterators