Iterators
An iterator is an object that implements an iterator protocol, and the iterator protocol in Python is that an object with the next method advances to the next result, and Stopiteration is raised at the end of a series of results.
In the For loop, Python automatically invokes the factory function iter () to get the iterator, automatically call next () to get the element, and also completes the
written in generator style:1 defGenerator_func ():2Wwwlog = open ("Access-log")3 #returns a Generator object using the generator expression (Generator expression)4Bytecolumn = (Line.rsplit (None, 1) [1] forLineinchWwwlog)5bytes = (int (x) forXinchBytecolumnifX! ="-")6 7 #The final step is calculated8 Print " Total", sum (bytes)As you can see, with generator, you can write less code and have a completely different programming style than normal Py
;list (I1) # automatic iteration [' MMMM ']> >>next (I2) Manual iterative Traceback for #i2 (mostrecentcalllast):file "The same is true for the generator function, where the statement-based DEF equivalent form supports only one active generator and is exhausted after one iteration.>>> def timesfour (S): For C in S:yield c * 4>>> G = timesfour ("spam") >>> iter (G) is Gtrue>> ;> I1, I2 = iter (g), ITER (g) >>> Next (I1) ' SSSs ' >>> Next (I1) ' PPPP ' >>> Next (I2) ' AAAA 'This differs from th
Easygui is based on tkinter, so it can be used across platforms.The use of the method is very simple, after download unzip the easygui.py into the Python installation directory under the lib/site-packages/can beImport Easygui Easygui.msgbox ("Hello, world! ")Import= Easygui.buttonbox ("what isyour favorite ice cream flavor? " " , = ['Vanilla','chocolate',' Strawberry']) easygui.msgbox ("" + flavor)Two simple code look at it
Python script has been written for a while, the advantages of the Python language does not have to say, but the GUI programming seems very few, looking for to find is the following two most reliable, but are the basis, really if the actual writing, but also to see the various code to do.
"Tkinter+programming+code+by+examples.pdf" http://vdisk.weibo.com/s/pNW4u
"T
Original Blog Address1, create a new. py file, such as test_hello.py;2. Right button, Edit with IDLE (i.e. Python GUI)3. Write code" Hello " Print (Hello) # ####################################test_list = [1,2,3,4,"minglang"] for in range (1,10): test_list.append (i)print (test_list)View Code4, Run->run module F5 Run program, the results are as follows5. DebugClick to open the Shell window of the debug
the code warehouse1. WxpythonWxpython is a python-based GUI library with the following advantages:
Cross-platform, 32-bit Microsoft Windows, most Unix/linux,mac
Open Source Free
Simple to use
Official documentation LinksGood English tutorials are suitable for the system to learn the use of various controls.2. Run a windowDirect instantiationImport WX# Each Wxpython program must have a
Absrtact: When programming with the Python process GUI, you often need to use the ListBox component, and how to control the display of the ListBox component, you need to use the ScrollBar component. This article focuses on the binding of actions between two GUI components--------the action of one component will start the corresponding action of another component.
): #每个组含有3个按钮 Radiobutton (root, variable = V, value = i, text = ' python ' + str (i)
). Pack () Root.mainloop ()
4.Radiobutton Another useful property is Indicatoron, which by default is 1, and if you change this property to 0, its appearance is sunkenFrom tkinter Import *root = Tk () v = Intvar () v.set (1) for I in Range (3): Radiobutton (root,
we continue to calculate the subsequent elements in the process of the loop? This eliminates the need to create a complete list, which saves a lot of space, and in Python, this side loop computes the mechanism called the generator: generatorThe generator is a special program that can be used as an iterative behavior for controlling loops, where the generator in Python is one of the iterators, using the yie
Python yield keyword, yield is a generator in PythonUnderstanding the builder needs to understand what the build is, the purpose of the slice is to cut out a portion of the existing list, and the purpose of the build is to build a list from scratchA built-in caseWhat can I do if I build a list of 10 elements?You can use Python's built-in function range to produce some numbers, and then use loops to populate
("ply"), and only if Grep_filter_co ("ply") has finished executing the suspend, Broadcast_co () will then send the data to the next coroutine.If you change the above code to this, there will be another mode of broadcast:f = open ("access-log"= Printer_co () Unix_tail_f_co (F, Broadcast_co ([ Grep_filter_co ('python', p)), Grep_filter_co ('ply ', p), Grep_filter_co ('swig', p)])
Tkinter is the standard GUI library in the python release version. That is to say, tkinter can be used after python is installed by default.
I have referenced a tutorial and wrote someCodeTry:
# File: test. pyfrom tkinter import * class app: def _ init _ (self, Master): Self. frame = frame (master) self. frame. pack () self. button = button (self. frame, text
, using width and heigth to specify the size of the control, what happens if the specified size does not meet the requirements of the text? The following code:Label (ROOT,BG = ' Welcome to jcodeer.cublog.cn ', width = 10,height = 3). Pack ()Run the program, the part of the text that goes beyond the label is truncated, and the usual method is to use the Wrap feature, and when the text length is greater than the width of the control, the text should be displayed on the next line, and TK will not b
') or Cv2.cv.FOURCC (* ' MJPG ').The following code captures the video from the camera, rotates each frame horizontally and saves it.ImportNumPy as NPImportCv2cap=Cv2. Videocapture (0)#Define The codec and create Videowriter objectFOURCC = Cv2. VIDEOWRITER_FOURCC (*'XVID') out= Cv2. Videowriter ('Output.avi', FourCC, 20.0, (640,480)) while(cap.isopened ()): RET, Frame=Cap.read ()ifret==True:frame=Cv2.flip (frame,0)#write the flipped frameOut.write (frame) cv2.imshow ('Frame', frame)ifCv2.waitke
-selected button state
Scale
A range control that displays a numeric scale that is a range of numbers for the output limit
Scrollbar
A scrollbar control that is used when the content exceeds a visual area, such as a list box ...
Text
Text control; for displaying multiple lines of text
TopLevel
A container control that provides a separate dialog box, similar to a frame
Spinbox
Input controls, similar to
If you want to use Python to develop a graphical interface, there are many tools to choose from, each with the pros and cons, previously used Wxpython+boa-constructor, has not been clear.
New understanding of the next PyQt4, seems to use this person also more, so decided to start learning this. Version:pyqt-py2.7-x86-gpl-4.9.1-1.exe
PyQt4 takes a QT designer and uses it to create an interface, layout controls such as Form,button,text, and so on, using
implicitly means that the function is returning control of the execution code to the place where the function is invoked. The implied meaning of "yield" is that the transfer of control is temporary and voluntary, and our function will reclaim control in the future.
In Python, a "function" with this ability is called a builder, and it is very useful. The generator (and yield statement) was first introduced
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.