In the process of using Python encountered a lot of problems, the knowledge point is scattered, through this paper to summarize.
One, Python's Itertools module
Combinations function: Combines the list by a given length.
from Import = [1, 2, 3, 4= [] for in range (1, len (seq) +1): result.append (List ( Combinations (seq, i)))
Results: [(1,), (2,), (3,), (4,), (+), (1,3) ... (1,2,4), ... (1,2,3,4)]
The Product function:
from Import = List (product ('abc'xy'= List (product ( Range (3), repeat=2))
result1:[(' A ', ' X '), (' A ', ' Y '), (' B ', ' X '), (' B ', ' Y '), (' C ', ' X '), (' C ', ' Y ')]
result2:[(0,0), (0,1), (0,2), (1,0), (+), (+), (2,0), (2,1), (+ 2,2)]
Second, Python invokes the SOA service, using the Suds module
def Testservice (): ' WSPL link Address of the service ' = suds. Client.client (URL) = dict (x='123') = Client.service.METHOPNAME (param) Methopname: From the SOA service function name
Third, Python sorts the dictionary elements in the list
Sort_list = [{'datestamp'2017-05'}, {' Datestamp'2017-04'}]sort_list.sort (Key= Operator.itemgetter ('datestamp'))
Iv. python conversion string encoding format
_str = _str.encode (encoding= ' UTF-8 ', errors= ' strict ')
V. Request data Module requests
When the requested URL requires username and password, you can use the following methods:
Import Requests def get_data (URL): = requests. Session () = (username, password) # user name and password s.headers.update ({' x-test'true'}) = s.get (URL, headers={'x-test2'true'})
Python uses essays