Here is my collection of some Python tips, is mainly a number of practical functions, suitable for a certain basis of children's shoes to watch (will not specifically describe the use of the standard library functions).
One, function-type
DefFindsmallest (arr):smallest=arr[0]smallest_index=0 For IInchRange1,Len (arr)): #smallest_index +=1 if arr[i] Smallest=arr[i] smallest_index=i return smallest_index def Selectionsort (arr): l=[] for i in range (len (arr)):
#-*-coding:utf-8-*-"""multi-threaded producer, consumers using queue queues"""ImportQueueImportThreadingImport TimeImportRandomqueue= Queue.queue (3)#Create a queue of 3 sizesclassProducer (Threading. Thread):"""producers, writing data to the queue""
Here is my collection of some Python tips, is mainly a number of practical functions, suitable for a certain basis of children's shoes to watch (will not specifically describe the use of the standard library functions).
One, function-type
1. Understand what exception handling isAn exception is a signal that an error occurs when the program is running (an exception occurs when the program fails, and if the program does not handle it, the exception is thrown and the program's operation
The RE module enables the Python language to have all the regular expression functionsTerminology Explanation:Pattern string:Optional flag parameters:' R ' is telling the compiler that this string is a raw string, do not escapeRe.match
This problem is mainly implemented by stacks. What is the stack, referring to the example of the suffix expression on the book to talk about their own understanding, the most obvious feature of the stack is the advanced post-out. So you can
I. Definition of functionsdef function name (argument list): function body return statementReturn statement does not write or no object behind it is return NoneTwo. Parameters of the functionNo parametersDef func1 (): print ("No parameters")
Given an array of integers, return indices of the both numbers such that they add-to a specific target.You may assume this each input would has exactly one solution, and you could not use the same element twice.Example :Given nums = [2, 7, one, +],
Summary: Contour discovery is a method based on image edge extraction to find the contour of an object, so the threshold selection of edge extraction affects the final contour discovery results.The code is as follows:ImportCv2 as CVImportNumPy as
There is a logging module in Python that can be used to record the relevant information, often using it in debug .1. Log LevelThe logs are divided into 5 grades, from low to High, respectively:
DEBUG
INFO
WARNING
ERROR
This task is still troublesome if you try it manually. It is decided to solve it by programming.
It is easier for python to handle task-related issues. It takes time to get started with Python and then writeCode, Very simple principle.
During
Package management tools in Python, including easy_install and Pip. Try installing Pip today.
Operation steps shown on the Internet
Preparation:
$ Curl-O http://python-distribute.org/distribute_setup.py$ Python distribute_setup.py When I run
The main technical special point is that the timer of pys60 can be set to 2147 seconds at most. It is written directly on the mobile phone. Import e32import audioimport timeimport appuifwimport sysimport OS. pathimport into aldef say (oclock): ""
This problem often occurs today. I am not very familiar with Web programming. Here I only record my solution:
First, check whether it is consistent with the followingCodeThe same is true for all key statements.
HelpThen confirm two points:
#
Subsections
Logs
Encoding
StringList and Dictionary
I. Logs
#! /Usr/bin/Python #-*-coding: UTF-8-*-''' created on @ Author: chenll Log Level notset
Console and test. log output:
2013-04-26 10:40:46, 381-log-Info-building table
Ii. Encoding
There
A dictionary corresponds to a list.
The dictionary is a set of unordered elements, so the offset is no longer used in the dictionary, instead of the key. It is a form of representation after data discretization. It uses a ing method to map keys to
UsePython+BeautifulsoupCompleteCrawlerCapture specific data and useDjangoBuild a management platform to coordinate crawling.
Because I like the Django admin background very much, I use this background to manage the captured links so that my crawlers
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