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.
Recently there was a small Web project that wanted to use the favorite Python, but I felt a shudder at the thought of the previous contact with Django, why? The Django configuration was too complex and the small project was not well suited to the
The list generation, which is the comprehensions, is a very simple and powerful build of Python built-in that can be used to create lists.
For example, to generate a list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] You can use range (1, 11):
>>> Range (1, 11)
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
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
There is no way to under a 2.6, if used 2.4 is too low, and toss, half a day to find Mysql-python-1.2.2.win32-py2.6.exe this installation file, installation complete, execute import mysqldb problems prompt:
File
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
In Python's standard library, _WINREG.PYD can operate the Windows registry, and the third-party Win32 library encapsulates a large number of Windows APIs, which are also handy to use. However, here is the use of _winreg operation of the registry,
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
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__ ('
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:
First of all to analyze the requirements, the Web application background needs authentication, the background page contains multiple pages, the most common method is to add authentication for each URL, but this requires each binding URL of the
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