These two days for a project written in Bottle+mongodb with the login function, but how can not get to save the cookie, the document to give us the code snippet to manipulate cookies:
@route ('/login ') def login (): username = Request. Forms.
Be familiar with the Python language and learn how Python is encoded.Be familiar with the Python library and know how to find the corresponding module when you encounter the development task.Know how to find and get a third-party Python library to
After installing CentOS5.9 (Final), execute #python and #python-v, see version number is 2.4.3, very old, and before written is run on python3.x above, 3.X and 2.X have a lot of different, interested friends can refer to this
There are defined fonts in the large frame of the website, including font size and color, which may be copied from other websites when the user publishes the article, and the copying process retains the font description information. When the article
1) doctest
Using Doctest is a similar approach to command-line attempts, and the usage is simple, as follows
The code is as follows:
def f (n):""">>> F (1)1>>> F (2)2"""Print (n)if __name__ = = ' __main__ ':Import DoctestDoctest.testmod ()
It
IDLE 3.0
>>> dic = {"AA": 1, "BB": 2, "AB": 3}
>>> DIC
{' AA ': 1, ' AB ': 3, ' BB ': 2}
>>> for K in Sorted (Dic.keys ()):
Print (k)
Aa
Ab
-----------------------------------------------
A Dictionary object is actually a key-value pair
Here
The copy of ********.bmp or copy of copy of ********.bmp such files are uniformly named ********0.bmp or ********00.bmp format, and the number of the following 0 represents ********. The number of BMP occurrences +1. Wrote a small script below:
The
The sample program is as follows:
>>> a = [-1, 3, ' AA ', 85] # define a list>>> A[-1, 3, ' AA ', 85]>>> del a[0] # delete No. 0 element>>> A[3, ' AA ', 85]>>> del A[2:4] # Removes the element starting from the 2nd element to the 4th. Including
The code is as follows:
def find_file_by_pattern (pattern= '. * ', base= ".", Circle=true):"' Find all the ' ' under a given folderRe_file = Re.compile (pattern)If base = = ".":Base = OS.GETCWD ()Final_file_list = []Print baseCur_list = Os.listdir
Previous article Python: Using the Threading module for multithreaded programming four [using lock mutex] we have started to relate to how to use mutexes to protect our public resources, now consider the following situation –
If you have more than
Introducing the next Psyco module today, the Psyco module will make your Python program run as fast as the C language.
It is said that Python language is easy to learn, but performance is much worse than some compiled languages (such as C), where
The IP regular is: R ' (([12][0-9][0-9]|[ 1-9][0-9]| [1-9]) \.) {3,3} ([12][0-9][0-9]| [1-9] [0-9]| [1-9]) '
Here is an example
#-*-Coding:utf-8-*-
Import re
def IP ():
' Verify the regular IP '
def match_group (P):
s = "' 211.210.209.108
Gan ffad1.2
For example:
Import MyModule
MyObject = Mymodule.myclass ()
Or
From MyModule import MyClass
MyObject = MyClass ()
If you want to create a class instance dynamically in your program, you have to take two steps, for example:
m = __import__ ('
More recently, analysis with programming joined Planet Python. As the first special blog of the site, I'll share how to start data analysis with Python. The specific contents are as follows:
Data importImport a local or web-side CSV file;Data
The usual module is OS, Os.path and Shutil, so introduce them first.
python traversing folders and files
This is perhaps the most commonly used feature, as follows:
The code is as follows:
Import OSImport Os.pathRootDir =
For example, convert a string to a character array:
thelist = List (thestring)
At the same time, we can easily traverse through the For statement:
For C in TheString:
Do_something_with (c)
To use such a statement:
result = [Do_something_with
1.open
Always remember to call the close () method of the file object after opening the file with open. For example, you can use the Try/finally statement to ensure that the file is closed at last.
File_object = open (' Thefile.txt ') Try:
Sometimes I ask myself, how do I not know in Python 3 in a simpler way to do "such" things, when I seek answers, over time, I certainly found more concise, effective and less bug code. Overall (not just this article), the total number of "those"
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