Looked at the doc of the function itself
Copy CodeThe code is as follows:
GetAttr (object, name[, default]), value
Get A named attribute from an object; GetAttr (x, ' Y ') is equivalent to x.y.When a default argument is given, it's returned when
First need to install the Chardet library, there are many ways, I just use a more stupid way: sudo pip install Chardet
Copy the Code code as follows:
#!/usr/bin/env python
# Coding:utf-8
Import Sys
Import OS
Import Chardet
Def print_usage
Python specific powerful library files, many features have corresponding library files, so it is necessary to learn, which has an FTP corresponding library file Ftplib, we only need the login function, and then use multi-threaded call the
SQLAlchemy's philosophy is that the magnitude and performance of SQL databases is important to object collections, and the abstraction of object collections is important for tables and rows.
One installation SQLAlchemy
Copy CodeThe code is as
Set up a two-fork tree node with a Data data field, Left,right two pointer fields
Copy CodeThe code is as follows:
#-*-Coding:utf-8-*
Class TreeNode (object):
def __init__ (self, left=0, right=0, data=0):
Self.left = Left
Self.right =
The Python break statement, like in the C language, breaks the minimum enclosing for or while loop. The break statement terminates the Loop statement, that is, the loop condition does not have a false condition, or the sequence is not fully
Brief introduction
Interested to see: Explanatory language + Dynamic type language + strongly typed language
Interactive mode: (mainly to test, you can try Ipython)
Copy CodeThe code is as follows:
$python
>>> print ' Hello World '
ScriptCopy
See the Internet also has open source code, this does not, I took to carry on two times rewrite, hehe, on the code:
Copy the Code code as follows:
#encoding: Utf-8
Import socket
From Hashlib Import SHA1
From random import Randint
From struct import
Random.randomRandom.random () is used to generate a random number of 0 to 1 points: 0
Random.uniformRandom.uniform (A, b), used to generate a random number of characters in a specified range, two parameters one of which is the upper bound, and the
Encapsulation is the process of converting a Python data object into a stream of bytes, and unpacking is the inverse of the package, converting bytes in a byte file or byte object into a Python data object, and not unpacking the data from the
Python2.7 writes the specified element in the HTML and generates the Excle file
Copy the Code code as follows:
#coding =GBK
Import string
Import Codecs
Import Os,time
Import XLWT
Import xlrd
From BS4 import BeautifulSoup
From XLRD import
Log file is generally generated by the day, then by the program to determine the date of the file and the current time, replace the monitoring log file
The program is just a simple example, monitor Test1.log for 10 seconds, turn to monitor Test2.log
Single thread implementation of multiple timers
newtimer.pyCopy the Code code as follows:
#!/usr/bin/env python
From HEAPQ Import *From threading Import TimerImport threadingImport UUIDImport timeImport datetimeImport SysImport Math
Global
Although I have encountered this problem in Python, it is easier to explain it in Ruby. In Ruby, there are many ways to traverse an array, the two most common are for and each:
Copy CodeThe code is as follows:
arr = [' A ', ' B ', ' C ']
Arr.each
1.DNS query process:
Take query www.baidu.com as an example
(1) The computer sends a request to the local domain name server to resolve the www.baidu.com(2) After the local domain name server receives the request, queries the local cache first, if
Batch modify Linux server password, generate EXECL table at the same time
Copy the Code code as follows:
#!/usr/bin/env python
#coding: UTF8
#随机生成自定义长度密码
From random import choice
Import String,pickle
def genpassword
I explained how the Raspberry Pi (Raspberry Pi) into a non-line, feeling every time through the command SSH management show trouble, so I write the Web interface, mainly using Python written CGI program, here to use the MINI_HTTPD this lightweight
1. Set up socket
Establishing a socket object requires knowing the type of communication and the Protocol family. The type of communication indicates what protocol is used to transfer the data. Examples of agreements include IPv4, IPV6, ipx\spx,
Questions raised:
Sometimes we collect the Web page, after processing the string to save to file or write to the database, this time need to develop a string encoding, if the collection page encoding is gb2312, and our database is utf-8, so do not
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