In micro-blog saw the article, and then try to translate a bit, some places do not understand, directly affixed to the original, but also hope to understand the people pointing.
# Fast Python Performance Tuning #
1.%timeit (per line) and%prun
Method One
If you do not use cookies, sending an HTTP POST is very simple:
The code is as follows
Copy Code
Import Urllib2, Urllibdata = {' name ': ' www ', ' password ': ' 123456 '}f = Urllib2.urlopen (url = '
1. Format of date output
All date and time APIs are within the DateTime module.
1. DateTime => String
1 now = Datetime.datetime.now ()
2 Now.strftime ('%y-%m-%d%h:%m:%s ')Output 2012-03-05 16:26:23.870105
Strftime is an instance method of a
The code is as follows
Copy Code
"Hello World" 1 Creating hello.py 2 Writing Program: if __name__ = = ' __main__ ':print "Hello World" 3 run Program: Python./hello.py Comments 1 Whether it is a line comment or a paragraph comment,
Example 1
The code is as follows
Copy Code
From Email.mime.text import Mimetext From Email.mime.audio import MimeaudioFrom Email.mime.image import MimeimageFrom Email.mime.multipart import Mimemultipart #发送邮件Def sendMail
Using Python to parse RSS is not a feedparse. Feedparse is a third party Python library that needs to be installed first
The code is as follows
Copy Code
# wget
An existing string, you need to remove the first paragraph separated by a space, as follows
>>> Product_model = ' ws-c2960g-24tc-l–fixed Module 0′>>> product_model.split (") [0]' Ws-c2960g-24tc-l '
Split () with no parameters takes all spaces
Format of:
1 str.split ([SEQ [, Maxsplit]]) We are most used to!
Name, age | Another user name, age
Name:haha,age:20|name:python,age:30|name:fef,age:55
Then we can cut the string object into a list by the split method of the string object.
A = '
When using Python to write an interactive program, the two internal functions that are often used are raw_input and input (most commonly or input), and this article looks at the difference between the two by some examples.
First, Raw_input1. Input
Python script:testpost.py
The code is as follows
Copy Code
Import UrllibImport Urllib2url = ' http://localhost/tools/testpost.php 'Values = {' Obs_year ': ' I ', ' name ': ' Tom ', ' sex ': ' Male '}data =
Tonight as usual. Open Aptana write Python program, a Has_key call error, the code is as follows:
The code is as follows
Copy Code
info = {}Info.has_key ("key")Console:Traceback (most recent call last):File "D:\workspace\
Python is a parsing language, so I need a Python parser first. I started out as a goofy apt-get install Python with Ubuntu, and it told me I had it installed.
Well, it's been installed. At the beginning we played in interactive mode (interactive
Just learned about Python recently, Python's Urllib module may be faster and simpler than PHP's curl. Put a little bit of code
The code is as follows
Copy Code
#_ *_ Coding:utf-8 _*_Import SysReload
The zlib module in Python is used to compress or decompress data for storage and transmission. It is the basis for other compression tools. Let's take a look at Python's method of compressing and decompressing strings and files using module zlib. If
If you have a batch of IP addresses that you want to get specific information about, such as belonging to the country, the city, and so on, the best way is to invoke the existing API interface to obtain, specific application scenarios can be based
Operations on files and folders (File operation functions) in python involve the OS module and the shutil module.Get the current working directory, that is, the directory path for the current Python script: OS. getcwd ()Returns all files and
There are several methods:1. Add the environment variable PYTHONPATH. python will add modules under this path and add the following lines in the. bashrc file:Export PYTHONPATH = $ PYTHONPATH:/usr/local/lib/python2.7/site-packages2. Add a path
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