)) # request.session.set_expiry(0) # request.session.set_expiry(None) return redirect(reverse(‘main:index‘))Storage session
Using the settings.py session_engine key, you can use the storage session to specify
Database-based sessions: This is the default Django session store, which needs to be added django.contrib.sessions to the Installed_apps settings, run manage.py migrate install the session table in the database, and display the specified
SESSION_ENGINE=‘django.con
(encode) the encoding format of the program that will be used to change the fileIv. description of Python functions1) Definition of function:def test1 (): Print ("The funtion")def test1 (x): #带参数 "The Funtion" X +=1 return xdef sum (A,b,*args): #*args receives n positional parameters, converts Narimoto group Print (a) Print (b) Print (args)def sun1 (**kwargs): #**kwargs receives n keyword arguments, converts to dictionaries Pr
;> fourth=raw_input()[32005>>>Months = endings = [,] + 17 * [+ [,] + 7 * [+ [= raw_input (= month_name = months [month_number-1 = day + endings [day_number-1 month_name + + ordinal + + yearView Code
>>>19741-12): 81-31): 161974
You can use the sharding operation to access elements within a certain range. The sharding is implemented through two indexes separated by colons:
>>> Tag >>>> tag [>>> tag [32:-4
The first index is the number of the first element to be extracted, and the last index is
Python beginners Summary 3: files, collections, functions, variables, etc,
I. File Operations:
File Operation Process:
1. open the file, get the file handle, and assign it to a variable.
2. Operate the file through a handle
3. close the file
File opening modes include:
R, read-only mode (default ).
W, write-only mode. [Unreadable; created if no data exists; de
Python day 9 (3) custom class, pythonday
1: __str _ (return user-friendly output)
1 >>> class Student(object): 2 ... def __init__(self, name): 3 ... self.name = name 4 ... 5 >>> print(Student('Michael')) 6
__str__()Returns the string that the user sees,__repr__()Returns the string that the developer sees
The list is the most basic data structure in Python. Each element in the sequence is assigned a number-its position, or index, the first index is 0, the second index is 1, and so on. (Python is called a list, while other language classes are called "arrays")Python has 6 built-in types of sequences, but the most common
: ' AB ', 4: ' AB '}Add, modifyIn [the]: dout[83]: {0: ' ab ', 1: ' Ab ', 2: ' AB ', 3: ' AB ', 4: ' AB '}in [+]: in [+]: d[' a '] = 5In []: dout[85]: {0: ' ab ', 1 : ' AB ', 2: ' AB ', 3: ' AB ', 4: ' Ab ', ' a ': 5}in [[D.update]: (' C ', 6)]) in []: dout[87]: {0: ' ab ', 1: ' Ab ', 2: ' AB ', 3: ' AB ', 4: ' Ab ', '
Knowledge Content:1. Recursive review2. Common algorithms3. Commonly used data structures4.python Cookbook algorithm and data structure collationResources:Http://python3-cookbook.readthedocs.io/zh_CN/latest/index.htmlHttp://www.cnblogs.com/alex3714/articles/5474411.htmlFirst, recursive review1. What is recursion: The function internally calls itself2. Characteristics of recursion
Must have a definite end condition
Each time you enter a de
3 ways to output an object in reverse in PythonJust use the list to illustrate it:>>> LST = [1,2,3,4,5,6]#Create a table#Method 1:>>> Lst1 = [i forIinchReversed (LST)]#reversed only works with sequences (lists, tuples, strings)>>>lst1[6, 5, 4, 3, 2, 1]#Method 2:>>> lst2 = sorted (lst,reverse=true)#Sorted+reverse applies To sequences (lists, tuples, strings), coll
, in which case a sequence of tuples is generated with the elements in the sequence parameter. Here's an example of using the map () function:Def Add_one (a): return a + 1def add_two (A, B): return a + bdef add_three (A, B, c): return a + b + ca = [1, 2, 3, 4, 5]b = [1, 2, 3, 4, 5]c = [1, 2, 3, 4, 5]result = Map (Add_one, a) print Resultresult = Map (Add
:", Len (str)) The result is:The length of STR is: 8
String index
A string is a sequence of characters that typically accesses a single character that consists of a string that can be indexed, and in N-character strings, the index starts at 0 and n-1 ends. A negative index is also allowed in Python, from the right-hand index of the string. The general form of a string index is:1str ="Goodluck"2 Print("the length of STR is:", Len (str))
, which can be used to copy mutable values such as lists or dictionaries, and not just copy references.If the list you want to copy contains a list, use the copy.deepcopy () function instead. The Deepcopy () function copies the list of colleagues inside them.>>>importcopy>>>list=[' A ', ' B ', ' C ']>>>newlist=copy.copy (list ) >>>newlist[1]=100>>>list[' A ', ' B ', ' C ']>>>newlist[' a ', 100, ' C ']>>>list=[1,2,3,[4,5,6,[7,8,9]]]>>>newlist1=copy.copy (list) >>>newlist1[
Install the Inception service and use Python 3 to audit MySQL. inceptionpython
Install the Inception service and use Python to audit MySQL
Bison is one of the packages that the Inception service depends on. However, some Linux versions have already installed Bison, or the Bison installed through yum, which is usually in version Bison 3.0 +.For the Inception pro
element is the same as its tag, this time cannot be positioned through the hierarchy, the index can be positioned as follows:driver.find_element_by_xpath("//select[@id=‘nr‘]/option[1]").click()driver.find_element_by_xpath("//select[@id=‘nr‘]/option[2]").click()driver.find_element_by_xpath("//select[@id=‘nr‘]/option[3]").click()The index here starts at 1, not the same as the Python index.
Python 3.x database connection example (pymysql mode), pythonpymysql
Because the MySQLdb module does not support Python3.x, you need to install the pymysql module if you want to connect to MySQL.
The pymysql module can be installed through pip. If you are using pycharm IDE, you can use project python to install a third-party module.
[File]> [settings]> [Project:
Tags: values having group SQL query order REM value repeat cachePython 3 MySQL SQL logical query statement execution order one, the definition order of the SELECT statement keywordSELECT DISTINCT
_number>Second, the execution order of the SELECT statement keyword1 (7) SELECT
2 (8) DISTINCT 3 (1) from 4 (3) 5 (2) On
True, otherwise false is returned.If the path parameter exists and is a folder, calling Os.path.isdir (path) returns True, otherwise false is returned.Using the os.path.exists () function, you can determine whether a DVD or flash drive is currently connected to your computer.>>> os.path.exists ('/tmp/1.txt ') true>>> os.path.isfile ('/tmp/1.txt ') true>>> Os.path.isdir ('/tmp/1.txt ') FalseFile read and write processPlain text files contain only basic text characters and do not contain font, si
Python basic 3 file functions,
Today, I will review the previous knowledge about file operations. The operations on files mainly consist of the following parts:
I. Basic file knowledge
1. Basic File Operations
File operations can be divided into three parts:
1. open the file, get the file handle, and assign a variable
2. Read and Write files using a handle
3. clo
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.