You can use doctest and unittest to perform unit tests in python.
1.doc test usage
(1) The Write Program is as follows (cubetest. py ):
#!/usr/bin/pythondef cube(x):"""cube a number and return the result>>> cube(2)8>>> cube(3)27>>>
Environment: Win7 + python 2.7.6
Import imageim1_image.open('3.png ') im. show ()
Display result:
Always show loading, cannot open, or the display content does not exist.
Double-click the image to display it normally.
Solution: (X: the python
8.5 logs
The Logging module provides a comprehensive and flexible log system. The simplest form is to send log information to a file or sys. stderr;
Import logging
Logging. debug ('destgging information ')
Logging.info ('ionional message ')
Logging.
Simple 'Hello World! '
Python command line
If you have installed Python, enter the following command in the Linux Command Line:
Copy codeThe Code is as follows:$ Python
Directly go to python. Then, at the command line prompt >>>, enter:
Copy codeThe
In the previous API test with httplib of Python 2.7, the running code is normal,
After using Python 3.3 recently, I checked the previous Code and found that the import httplib has an error: Unresolved import: httplib,
When running the code, the
Preface to capturing novels using PythonThis script is written to capture novels on MAC. You can use a few pieces of Python code.
Code
# Coding = utf-8import reimport urllib2import chardetimport sysfrom bs4 import BeautifulSoupimport codecsclass
Description of the range Function: range ([start,] stop [, step]) generates a Sequence Based on the range specified by start and stop and the step size set by step.Range example:Copy codeThe Code is as follows: >>> range (5)[0, 1, 2, 3, 4]>>> Range (
This article corresponds to exercise 39 dictionaries and cute dictionaries.
# Encoding: UTF-8 # differences between the list and dictionary # list thing = ['name', 1, 'age', 'ad ', 'sex'] print thing [1] # print thing ['name'] # An error is
Get a worksheet
table = data.sheets()[0] table = data.sheet_by_index(0) table = data.sheet_by_name(u)Get the value of the whole row and the whole column (returned array)Obtain the number of rows and columns6. Get CellsWhen I used it
Form request, post, get
First, let's take a look at the Request object, which contains some useful information. It is no stranger to anyone who has learned B/S development, let's take a look at how Django is implemented:
Attribute/Method
A lot of code has recently shared this question. The question is about object-oriented or functional programming. The following is an example of PYTHON implementation.
Copy codeThe Code is as follows:#! /Usr/bin/python# Encoding: utf8
'''The Game of
I encountered Encoding Problems in the python code I wrote: SyntaxError: Non-ASCII character '\ xd3' in file crawler. py
Cause: the Code contains a part that needs to output Chinese characters, but this error occurs during running;
Error prompted
1. output with commas
Print to print the expression-whether it is a string or a string of other types after automatic conversion. It is also feasible to print multiple expressions, as long as they are separated by commas:
>>> ,4242 >>> 1,2,31, 2, 3>
1. view the current Python version
Python-V
2. view the current CentOS version.
Cat/etc/redhat-release
3. Install all Development Kits
Yum groupinstall
4. install other required packages
Yum install zlib-devel bzip2-devel openssl-devel
Stores strings separated by commas in a field and returns a corresponding list.
Copy codeThe Code is as follows:From django import formsFrom django. db import modelsFrom django. utils. text import capfirstFrom django. core import exceptions
Class
1. Start with Kmeans
Kmeans is a very basic clustering algorithm that uses the idea of iteration. We will not talk about its principles here. The following describes how to use the kmeans Algorithm in matlab.
Create seven two-dimensional data points:
1. What is Numpy?
Numpy is a Python scientific computing library that provides matrix computing functions. It is generally used with Scipy and matplotlib. In fact, list already provides a representation similar to a matrix, but numpy provides more
Because I want to use Python to implement a distributed system to manage and monitor the content and running status of CDN, I accidentally met RabbitMQ and many people are recommended, for example, why do I choose RabbitMQ.
It took me several hours
A function with yield is a generator, which is different from a common function. Generating a generator looks like a function call, but does not execute any function code until it calls next () (next () is automatically called in the for loop to
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