The first chapter introduces
Scripting languages are languages similar to DOS batches and UNIX shell programs. The scripting language does not need to be executed every time, and it is easy to access the running program in the execution, and even
A good integrated development environment, can greatly improve the programming efficiency. So, I need to find a good python development tool first.
Eclipse +pydev, it feels good. I put the key points of the installation process in detail in this
1. The use of measuring tools, quantitative performance can improve performance, commonly used timeit and memory_profiler , in addition to, profile cProfile , hotshot etc., memory_profiler used psutil , so can not track cpython the expansion;
2. c
For example, the following examples:
Class Book(Object):Def __setattr__(Self, Name, Value):If Name == ' Value ':Object.__setattr__(Self, Name, Value - 100)Else: Object.__setattr__(Self, Name, Value)Def __getattr__(Self, Name):Try:Return
Example one: Use Httplib to access a URL and get what it returns:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
Import HttplibConn=Httplib. Httpconnection
Copy Code code as follows:
#-*-Coding:utf-8-*-
From win32com.client import Dispatch
if __name__ = = ' __main__ ':
App = Dispatch ("et"). Application ")
# Small version number
print ' app. build:%s '% App. Build
# Large Version number
No way on the next 2.6, if the 2.4 is too low, and toss, half a day to find the Mysql-python-1.2.2.win32-py2.6.exe this installation file, installation completed, the implementation of import MYSQLDB problems prompted:
File
1) doctest
Using Doctest is a similar way to command-line attempts, and the usage is simple, as follows
Copy Code code as follows:
def f (n):
"""
>>> F (1)
1
>>> F (2)
2
"""
Print (n)
if __name__ = = ' __main__ ':
For example, to convert a string object s from GBK inner code to UTF-8, you can do the following
S.decode (' GBK '). Encode (' utf-8′)
However, in actual development, I have found that this approach often appears to be abnormal:
Unicodedecodeerror: '
Local name Static detection
When Python detects a local scope: it is detected when Python compiles code, not through their assignment at runtime.
In normal circumstances, a name that is not copied in a function will be found in the module that
The sqlite3 itself does not natively provide a dictionary-like cursor as pymysql.
cursor = conn.cursor (pymysql.cursors.DictCursor)
But the official document has already reserved the corresponding implementation plan.
def dict_factory (
This example describes the common basic operations of Python files and folders. Share to everyone for your reference, specific as follows:
1, to determine whether the file (folder) exists.
Os.path.exists (Pathname)
2, determine
For example: ' String ', ' string ', ' ' ' ' string ' ', ' or ' '.
In use, single and double quotes are no different. The main function of triple quotes is to include line wrapping in a string. In other words, the string in three quotes, if the
First, introduce the IF-ELSE conditional statement. If statements are used to selectively execute specific program blocks based on the true and false expression, the process of the control procedure. Use the same languages as Java. For else if,
Copy Code code as follows:
#Filename: brn.py
#Description: Batch Replace certain words in file names
#Use to bat Rename the "file in a dir" (Modify the suffix from "A to B") for Windows Vista OS
Import Sys
Import OS
Import Fnmatch
Import
opts, args = Getopt.getopt (sys.argv[1:], "t:s:h", ["walletype=", "servicename=", ' help '])
For A,o in opts:
If a in ('-t ', '--walletype '):
Walle_type = O
Elif A in (' s ', '--servicename '):
service_name = O
Elif A In ('-H ', '--help '):
Help =
1.match () Start match from start position2.search () Any position matching, if there are multiple matches, only return the first3.finditer () returns all matches4. Each match is the maximum match possible. For example:>>> m = re.compile (' abc[bcd]*
Theory does not say much:
Copy Code code as follows:
#!/usr/bin/python
Import Sys
def merge (array, q, p, r):
Left_array = array[q:p+1]
Right_array = array[p+1:r+1]
Left_array_num = Len (left_array)
Right_array_num = Len
QUICKSORT (A, p, R) is a fast-sequencing subroutine that calls the partitioning program to partition the array, and then recursively calls QUICKSORT (A, p, R) to complete the quick sort process. The worst time complexity for fast sorting is O (N2),
The following is the final code (implemented under Windows)
Copy Code code as follows:
#-*-coding:cp936-*-
Import OS
Path = ' d:\\ picture \ \ '
For file in Os.listdir (path):
If Os.path.isfile (Os.path.join (path,file)) ==true:
If
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service