1. generate random number import random # This is a comment, introducing the module RND = random. randint (1,500) # generate a random number between 1 and. read File F = open ("C: \ 1.txt"," R ") lines = f. readlines () # Read all content for line in lines print line3. Write File F = open ("C: \ 1.txt"," R + ") # readable and writable mode f. write ("123") # Write a string 4. regular Expression to read Tomcat logs and print the date import re regx = "\ D-\ D +" F = open ("C: \ stdout. log "," R ") I = 0 for STR in F. readlines (): If re. search (regx, STR): Response. write (STR + "<br>") if I> 10: break # because it is a test, only ten rows of I = I + 1 F are analyzed. close (); 5. import pgdbconn = pgdb. connect (host = 'localhost', Databse = 'qingfeng', user = 'qingfeng', password = '000000') cur = Conn. cursor () cur.exe cute ("select * From dream") print cur. rowcount6.sax processing XML: Import string from XML. sax import saxlib, saxexts class quotationhandler (saxlib. handlerbase): "crude sax Extractor for quotations. DTD document "def _ init _ (Self): Self. in_quote = 0 self. thisquote = ''def startdocument (Self): print '--- begin document --- 'def startelement (self, name, attrs): If name = 'quotation': Print 'quotation: 'self. in_quote = 1 else: Self. thisquote = self. thisquote + '{'def endelement (self, name): If name = 'quotation': print string. join (string. split (self. thisquote [: 230]) + '... ', print' ('+ STR (LEN (self. thisquote) + 'bytes) \ n' self. thisquote = ''self. in_quote = 0 else: Self. thisquote = self. thisquote + '}' def characters (self, CH, start, length): If self. in_quote: Self. thisquote = self. thisquote + CH [start: Start + Length] If _ name _ = '_ main _': parser = saxexts. xmlparserfactory. make_parser () handler = quotationhandler () parser. setincluenthandler (handler) parser. parsefile (open ("sample. XML ") parser. close () 7. python's GUI module standard is tkinter, and there are also QT and MFC modules. If you are interested, search for import tkinter root = tkinter. TK () My = label (root, "Welcome to Python's world") My. pack () root. mainloop ()