Tag: PAC request err cal write exit span tab com
1PYTHON data structure:1: Sequence:
list (can be changed)
Ganso (cannot be changed)2: Map:
dictionary 3: Unordered:
collection ASCII: Eight-bit unicode:16 bit
Functions of 2PythonABS: Absolute valuematch.sqrt: Prescribe
Match.ceil: On-entry
Match.floor: Next entryPOW: Power
repr: Stringstr: StringRound: RoundingHelp: HelpingInput: Enterraw_input: Raw inputcamtch.sqrt: Negative root
3Python of Operation
(1) command line Run Program: Python hello.py
(2) run the script like a normal program: #!/usr/bin/env python on the first line of the program
re-run: hello.py or./hello.py
module: A set of functions used for program extensions(1) Import matchmatch.sqrt (+)(2): From match import sqrtsqrt (+)
the + sign can only connect strings and cannot concatenate strings and numbersto first turn the number into a string: Three ways:
str repr ' Example: temp=32>>>print "I am Chennan" +' temp ' I am Chennan 32
can be
4 string is immutablesplit: Split stringStrip: Remove the spaces on both sides, not including the internal
5 lists: List function, can change sequence>>>x=[1,2,3,4,5]1: Delete element: del x[1]2: Shard element: x[2:]=[1,1,1,1]3: Append: element: Appendlist: Extend4: Inserting: Insert X.insert (3, ' 5 ')5: Counts: count6: Indexes: Index7: Remove: Pop: return value x.pop ()8: Sort: x.sort ()
9: Reverse: Reverse X.reverse ()
6 progenitor: tuple function, immutable sequence(4,2,1,2,5,3,7)>>>tuple ([1,3,4,5,2])(1,3,4,5,2)
The tuple function can change the list to Cheng Yuanju
7 dictionaries: The form of key-value pairs1:x={"Chen": "A", "Liu": "+", "Xu": "A " 2:>>>item=[("name", Chen ""), ("Age", "a")]>>> x=dict (item)x={"name": "Chen", "Age": "A",}
Dictionary method:clear: Empty
Copy
: Duplicate get: Access Fromkeys: Build dictionary with given key _key: Determine if there are keys items: Convert dictionary to list popitem: Randomly delete elements
8 Set-up: unordered sequence construction
Set ([1,2,3,4,5,6,7])
9 FunctionsPrint statement Prints values separated by multiple commasimport .... as ..... Import functions and make Office rename Departmentexec: Execute statementeval: Evaluating an expressionPass: Do nothingdel: Delete Judgment statement: if
elif Checking multiple conditional statements: shorthand for else if Else
10: module:module is a programmodules are used to define functionsA package is a collection of modulesstandard libraries in the module: 1:sys:Path : Pathsstdin: Standard input streamstdout: Standard output streamargv: command-line ArgumentsExit : Exit informationModules: Mapping the module name to the dictionary loaded into the modulestderr: standard error stream 2:os:Envior: Mapping for environment variablesSep: Delimiter in pathpathsep: path character for split pathlinesep: Line delimiter 3:fileinputFileName: NameClose : Closing sequenceNextfile: Next 4:timeSleep : Hibernate
Time: Currentastime ([tuple]): Converting a time-primitive ancestor to a stringMktime (tuple): Convert time progenitor to local time
LocalTime ([sec]): Converts the number of seconds into a time-cell ancestor 5:random: Random function 6:re: Regular typeMatchCompileSearchSplitFindAllSubEscape 7:shelve:Create a persistent mapping while preserving the mapped beauty in the database of the given file name.
Network Programming:Socket Programming: Sockets are primarily information channels between two processes, which may be distributed across different computers and receive information from one another through sockets.
A small server :Import SocketS=socket.socket ()Host=socket.gethostname ()port=1234S.bind ((host,port)) S.listen (5)While true:c.addr=
s.accept () print "I am Chen Nan", addrc.
send("Hello Boy")c.
close()
a small client:Import SocketS=socket.socket ()Host=socket.gethostname ()port=1234S.connECT ((Host,port))print S.recvz (1024x768)
urllib and URLLIB2 modules1: Open remote fileFrom urllib import Urlopenwebpage=
urlopen("http://www.baidu.com")2: Get remote FilesUrlretrieve ("http://www.baidu.com", "C\chennan.xml")
socketserver Framework : Synchronous network server base class: It's easy to write a server that can handle mixed classes with forks and threads. consists of four base classes:1:tcpserver2:udpserver3:unixstreamserver4:unixdatagramserver
Write a socketserver server program
Most of the code is in the request handler: RequestHandler
If you are using a stream, you can use the StreamrequesthandlerSelf.rfile for readingSelf.wfile for writing From socketserver import tcpserver,
streamrequesthandler
class Handler(Streamrequesthandler)def handle (self)addr=self.request.getpeername (0print "I am Chennan", addrself.wfile.write ("Hello boy")Server=tcpserver (("", 1234), Handler)Server.server_forver ()
SQLite Database
need to download Pysqlite's Windows edition and SQLite firstImport Sqlite3conn=sqlite3.connect ("somedatabase.db")curs=conn.cursor ()//Get cursorconn.cmmmit ()//Submitconn.close ()//Off
cursor cursor (): Execute SQL query through cursor and test resultsresults can be obtained one by one, or can be obtained by many together.
Python and the World Wide Web
Urllib and Urlopen and re regular Expressions crawl Web pagesBeautiful Soup is a small module used to parse and examine the non-canonical HTML that is seenCGI: A common Gateway interface, which is a standard mechanism by which a Web
server can pass query results (
typically Web Forms ) to specialized programs, such as
python programs, and display results on a Web page.
CGI modules and Cgitab modules are useful for writing CGI steps
Mod_python: Handler framework makes it possible to write Apache frameworks in Pythonthere are three standard handlers1:cgi Processing program2:PSP Processing program3: Release HandlerWeb application framework: Django Framework
Python Learning Notes Summary