Class variables are defined immediately after the class name, which is equivalent to static variables of Java and C ++.
Instance variables are defined in _ init _, which is equivalent to common variables in Java and C ++.
>>> Class test: COUNT
Module:
The module contains PythonCode. Use import to import modules to otherProgram.
Each module has its own namespace. The code in the main Python program is associated with a clear space named _ main. When you place the code in a separate
1. Extract non-repeated data from the array
>>> A = [x * 2 for X in range (1, 5)] * 2
>>> Uniq = List (SET ())
[8, 2, 4, 6]
>>> Uniq = sorted (SET ())
[2, 4, 6, 8]
>>> B = {}
>>> For X in:
... B [x] = 1
>>> Uniq = B. Keys ()
2
For details about the python urllib module and an example, let's look at an example. This example captures the HTML of the Google homepage and displays it on the console:
Import urllib
Print urllib. urlopen ('HTTP: // www.google.com '). Read ()
Python login Simulation Implementation
This article mainly uses python to simulate website logon. Construct post data by yourself to implement the login process using python.
When you want to simulate a website login, you must first understand the
Number = 23; # define variablesGuess = 22;If number = guess: # If judgment, note: no lessPrint 'yse'; # note that indentation in python can be used only when it is included.Elif number> guess: # note that it is not else if but ElifPrint 'Big
When using OGR in Python, you must first import the OGR library. If you need Chinese support, you also need to import the gdal library. The specific code is as follows. Result 1 of SHP created by python is shown.
Figure 1 create a vector in Python
Mymodule. py:
#-*-Coding: UTF-8-*- Import sys # import the entire string module print sys. path ''' if you use from import sys , you can directly use stdout on this page. write () otherwise, sys. stdout. write () ''' def main (): sys.
Sometimes, you need to package the python program project, that is, to package only the python file compiled after the python file, you need to compile the python file.
There are two compilation methods:
1. Write a python simplified version to
Supports zips, RARs, 7zips, tar.gz, and more.
Enter the compressed file name and return an XML file structure.
#! Usr/bin/Python
# Coding = UTF-8Import UUIDImport OSImport zipfileImport reImport sysImport officetoimageImport rarfileImport
Just for fun
Server = wsgiserver. cherrypywsgiserver ('0. 0.0.0 ', 8000), APP)Server. Start ()
Is the program entry, where app is your application
Def app (Environ, start_response ):Out = 'tmp/'{str(uid.uuid1({{}'.zip'Status = '100 OK'Filename =
I. Introduction
The crawler contains two classes: one for managing the entire crawler process and one for retrieving and parsing each Downloaded web page (retriever ).Ii. Procedures
#!/usr/bin/env pythonfrom sys import argvfrom os import
Python POST request
Previous/Next Article 10:29:15/person type: PythonView (176 )/
Comment (0 )/
Score (0/
0)
Post Method 1:
The request data format is:
test SME-MEETING 006317 user@163.com etester memo
Remove You can directly use Python
Repost this article to indicate the source in the form of a link.
1. Preface
Python can capture many packages, such as urllib, urllib2, httplib, and httplib2. Httplib and httplib2 specifically process HTTP-related data, while urllib and urllib2 are
Log on to the website using Python
For most forums, we need to log in first to capture the posts for analysis. Otherwise, we cannot view them.
This is because the HTTP protocol is a stateless (stateless) protocol. How does the server know whether
1. Read Excel
Here we will introduce a good package xlrs that can work on any platform. This means that you can read Excel files in Linux.
First, open the workbook;
Import xlrd
WB = xlrd.open_workbook('myworkbook.xls ')
Check Form Name:
WB.
#! /usr/bin/env python# -*- coding:utf-8 -*-import sysclass sort(object) : @classmethod def __bubble_sort(cls, data = [], start = 0, end = -1) : if end len(data) : end = len(data) if end data[j] :
A code line statistics Tool written in python. The file name is counter. py. You can collect comments, code lines, empty lines, and total lines in the code file. Currently, the comments are //,/*... */, and the comments are # type. Usage:
Create a
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