日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python3常用代码块汇总

發布時間:2024/1/1 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python3常用代码块汇总 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文章主要用于平時Python3學習和使用中積累的比較常用的代碼塊。代碼都是經過驗證可行的。

一、基本數據類型

字符串

字符串常識:

  • 可以利用反斜杠(\)對雙引號轉義:",或者用單引號引起這個字符串。例如:‘I l"o"ve fishc.com’
  • 字符串支持分片,如:Str1[:6] 返回字符串前6個字符 ,0-5 index

字符串的方法(都要用dot),返回一個新的字符串,原來不變。例如字符串s, s.capitalize()返回一個新的字符串。

# 字符串相加 >>> print("nihao"+"a") nihaoa# 字符串乘整數,連續輸出8次,相當8次字符串相加 >>> print("nihao\n"*3) nihao nihao nihao# 在前面的字符串后面打印后面的字符串,再循環中使用很方便,例如用new line mark or space >>> print("不分手的", end="戀愛") 不分手的戀愛# 獲得字符串長度 >>> len("chilema") 7# 在一個字符串的每個字符之間插入一個字符串 >>> str1 = "sh" >>> str1.join("12345") '1sh2sh3sh4sh5'

進制轉換

#十進制轉換二進制 >>> bin(10) '0b1010'

隨機數

Python自帶random庫支持模擬多種分布,包括Beta、Exponential、Gamma、Gaussian、Log normal distribution、Pareto distribution、Weibull distribution等,具體見 random — Generate pseudo-random numbers

Basic samples

>>> from random import * >>> random() # Random float: 0.0 <= x < 1.0 0.37444887175646646>>> uniform(2.5, 10.0) # Random float: 2.5 <= x < 10.0 3.1800146073117523>>> expovariate(1 / 5) # Interval between arrivals averaging 5 seconds 5.148957571865031>>> randrange(10) # Integer from 0 to 9 inclusive 7>>> randrange(0, 101, 2) # Even integer from 0 to 100 inclusive 26>>> choice(['win', 'lose', 'draw']) # Single random element from a sequence 'draw'>>> deck = 'ace two three four'.split() >>> shuffle(deck) # Shuffle a list >>> deck ['four', 'two', 'ace', 'three']>>> sample([10, 20, 30, 40, 50], k=4) # Four samples without replacement [40, 10, 50, 30]

Simulations

>>> # Six roulette wheel spins (weighted sampling with replacement) >>> choices(['red', 'black', 'green'], [18, 18, 2], k=6) ['red', 'green', 'black', 'black', 'red', 'black']>>> # Deal 20 cards without replacement from a deck of 52 playing cards >>> # and determine the proportion of cards with a ten-value >>> # (a ten, jack, queen, or king). >>> deck = collections.Counter(tens=16, low_cards=36) >>> seen = sample(list(deck.elements()), k=20) >>> seen.count('tens') / 20 0.15>>> # Estimate the probability of getting 5 or more heads from 7 spins >>> # of a biased coin that settles on heads 60% of the time. >>> def trial(): ... return choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5 ... >>> sum(trial() for i in range(10_000)) / 10_000 0.4169>>> # Probability of the median of 5 samples being in middle two quartiles >>> def trial(): ... return 2_500 <= sorted(choices(range(10_000), k=5))[2] < 7_500 ... >>> sum(trial() for i in range(10_000)) / 10_000 0.7958

Simulation of arrival times and service deliveries for a multiserver queue

from heapq import heappush, heappop from random import expovariate, gauss from statistics import mean, median, stdevaverage_arrival_interval = 5.6 average_service_time = 15.0 stdev_service_time = 3.5 num_servers = 3waits = [] arrival_time = 0.0 servers = [0.0] * num_servers # time when each server becomes available for i in range(100_000):arrival_time += expovariate(1.0 / average_arrival_interval)next_server_available = heappop(servers)wait = max(0.0, next_server_available - arrival_time)waits.append(wait)service_duration = gauss(average_service_time, stdev_service_time)service_completed = arrival_time + wait + service_durationheappush(servers, service_completed)print(f'Mean wait: {mean(waits):.1f}. Stdev wait: {stdev(waits):.1f}.') print(f'Median wait: {median(waits):.1f}. Max wait: {max(waits):.1f}.')

MD5 hash

import hashlib # 導入hashlib模塊md = hashlib.md5() # 獲取一個md5加密算法對象 md.update('how to use md5 in hashlib?'.encode('utf-8')) # 制定需要加密的字符串 print(md.hexdigest()) # 獲取加密后的16進制字符串

判斷變量的類型

>>> tmp = [1,2,3] >>> isinstance(tmp, list) # Out: True

二、循環

跳出多層循環

for … else … break

else中的語句是在for循環所有正常執行完畢后執行。所以如果for中有break執行的話,else的語句就不執行了

for i in range(5):for j in range(5):for k in range(5):if i == j == k == 3:breakelse:print(i, '----', j, '----', k)else: continuebreakelse: continuebreak

上面程序執行到i=j=k=3的時候就跳出所有循環了,不再執行

利用flag變量

a = [[1, 2, 3], [5, 5, 6], [7, 8, 9]] for i in range(3):for j in range(3):if a[i][j] == 5:flag = Falsebreakif not flag:break

自定義異常

class StopLoopError(Exception): pass try:for i in range(5):for j in range(5):for k in range(5):if i == j == k == 3:raise StopLoopError()else:print(i, '----', j, '----', k) except StopLoopError:pass

三、函數

  • set the default value of arguments def my_func(a, b=5, c=10):
  • keywords arguments(named arguments): my_func(a=1, c=2)
  • *args is used to scoop up variable amount of remaining positional arguments(it is a tuple). You cannot add more positional arguments after *args, the parameter name can be anything besides args。unless you use keyword(named) arguments. i.e. def func1(a, b, *args, d): func1(1,2,3,4,d=30)
  • **kwargs is used to scoop up a variable amount of remaining keyword arguments(it is a dictionary). Unlike keyword-only arguments, it can be specified even if the positional arguments have not been exhausted. No parameters can come after **kwargs
  • def func1(a, b, *args):print(a, b, args)func1(1,2) #如果不給*args值,就返回一個空的元組 # out: 1 2 () l = [1,2,3,4,5] func1(*l) # unpack a list as arguments # out: 1 2 (3, 4, 5)# 求平均數 # a and b,如果兩個都為真,返回第二個,如果一個真一個假或者兩個都假返回False或者第一個值。 # a or b,如果兩個都為真,返回第一個值,如果一個真一個假,則返回真的值,如果兩個都假則返回第二個 def avg(*args):count = len(args)total = sum(args)return count and total/count # 通過and判斷函數是否有參數輸入# to force no positional arguments,you can only give keyword argument when you call the function def func(*, d): #code# * shows the end of positional parameters def func(a, b, *, d): # you can only pass two positional arguments, and here d is keyword parameter#code def func(*, d, **kwargs):print(d, kwargs) func(d=1, a=2, b=3, c=4) #out: 1 {'a': 2, 'b': 3, 'c': 4}# use *args and **kwargs together def func(*args, **kwargs):print(args, kwargs)func(1, 2, b=3, c=4, d=5) #out: (1, 2) {'b': 3, 'c': 4, 'd': 5}# cached version of factorial, no more calculation for calculated number def factorial(n, cache={}):if n < 1:return 1elif n in cache:return cache[n]else:print("caculation {0}".format(n))result = n * factorial(n-1)cache[n] = resultreturn result

    Lambda Expression (Anonymous Function)

    # lambda with one input >>> g = lambda x: 3*x + 1 >>> g(3) 10#lambda with multiple input(two or more), e.g. combining first name and last name #strip() is to remove the leading and trailing whitespace. #title() is to ensure the first letter of each string is capitalized >>> full_name = lambda fn, ln: fn.strip().title() + " " + ln.strip().title() >>> full_name(" ZHAng ", "sAN") 'Zhang San'#sort list by key using lambda >>> list_example = ["9 jiu", "1 yi", "5 wu", "3 san"] >>> list_example.sort(key = lambda word: word.split(" ")[0]) >>> list_example ['1 yi', '3 san', '5 wu', '9 jiu']#function returns function, e.g. Quadratic Functions f(x) = ax^2 +bx + c >>> def build_quadratic_function(a, b, c): ... return lambda x: a*x**2 + b*x + c ... >>> f = build_quadratic_function(1, 3, 2) >>> f(0) 2 >>> f(1) 6

    Reducing function arguments (partial function)

    This is just to reduce the number of arguments you need to pass when you call the original function. Sometimes, this is useful because some higher-ordered function can only accept one-parameter function as his arguments, you can see it in the following example.

    # calculate the distance from some points to the origin in a x-y coordinate. origin = (0, 0) l = [(1,1), (-3, -2), (-2, 1), (0, 0)] dist = lambda a, b: (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2# the above function needs two arguments, but you want to pass this function to sorted function which can only accept a one-parameter function. So you need to reduce it.from functools import partial f = partial(dist, origin)print(sorted(l, key=f))# you can also use lambda function print(sorted(l, key=lambda x: dist(x, origin)))

    四、容器及其操作

    集合Set

    #modify sets >>> example1 = set() >>> example1.add("yi") # 添加元素 >>> example1.add("er") >>> example1.update([1,4],[5,6]) # update可以同時添加多個元素 >>> example2 = set([28, True, 3.14, "nihao", "yi", "er"]) >>> len(example)# 移除元素 >>> example2.remove(x) # 將元素 x 從集合 example2 中移除,如果元素不存在,則會發生KeyError錯誤 >>> example2.discard("Facebook") # 不存在不會發生錯誤 >>> example2.clear() # 清空集合 >>> x = example2.pop() # 隨機刪除集合中的一個元素賦值給x# evaluate union and intersection of two sets >>> example1.union(example2) >>> example1.intersection(example2) >>> "nihao" in example2 # 查看元素是否在集合內 True >>> "nihao" not in example2 False# 兩個集合間的運算 >>> a = set('abracadabra') >>> b = set('alacazam') >>> a {'a', 'r', 'b', 'c', 'd'} >>> a - b # 集合a中包含而集合b中不包含的元素 {'r', 'd', 'b'} >>> a | b # 集合a或b中包含的所有元素 {'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'} >>> a & b # 集合a和b中都包含了的元素 {'a', 'c'} >>> a ^ b # 不同時包含于a和b的元素 {'r', 'd', 'b', 'm', 'z', 'l'}>>> example1.isdisjoint(example2) # 判斷兩個集合是否包含相同的元素,如果沒有返回 True,否則返回 False >>> issubset() # 判斷指定集合是否為該方法參數集合的子集

    元組Tuple

    • 一旦定義,不能改變,不能再賦值,不能用del刪除某個元素,只能刪除整個元組
    • 元組的切片方法和列表一樣
    • 創建空元組:temp=()
    • 創建一個數的元組:temp=(1,) 必須加逗號,括號可以不加
    • 改變一個元組的辦法,例如 temp=(1,2,3,4),令 temp = temp[:2] + (6,) + temp[2:] 輸出temp 為 (1,2,6,3,4),這是元組的拼接,同樣適用于字符串。
    >>> temp = 1,2,3 >>>temp (1, 2, 3)>>> 8*(8,) (8, 8, 8, 8, 8, 8, 8, 8)

    Unzip a list of tuples

    zipped_list = [(1, 'a'), (2, 'b'), (3, 'c')] list_a, list_b = zip(*zipped_list) print(list_a) # out: (1,2,3) print(list_b) # out: ('a', 'b', 'c')

    Iterators returns only elements at a time. len function cannot be used with iterators. We can loop over the zip object or the iterator to get the actual list.

    list_a = [1, 2, 3] list_b = [4, 5, 6]zipped = zip(a, b) # out: zip object len(zipped) = # out: TypeError: object of type 'zip' has no len() zipped[0] # out: zip object is not subscriptable list_c = list(zipped) # out: [(1,4), (2,5), (3,6)] list_d = list(zipped) # out: [] is empty list because of the above statement

    Named tuples

    Named tuples subclass tuple, and add a layer to assign property names to the potential elements. It is located in the collections standard library module. Named tuples are also regular tuples, we can still handle them just like any other tuple(by index, slice, iterate). Named tuples are immutable.

    from collections import namedtuple '''it is a function(class factory) which generates(return) a new class that inherits from tuple. The new class provides named properties to access elements of the tuple and an instance of that class is still a tuple''''''namedtuple needs a few things to generate this class: 1.the class name we want to use 2.a sequence(list, tuple) of field names(strings) we want to assign, in the order of the elements in that tuple '''Point2D = namedtuple('Point2D', ['x', 'y']) # the variable initial is capitalized, because it receives a class returned from the fucntion #the following three ones have the same effect #Point2D = namedtuple('Point2D', ('x', 'y')) #Point2D = namedtuple('Point2D', 'x, y') #Point2D = namedtuple('Point2D', 'x y') '''in fact, the __new__ method of the generated class uses the field names we provided as param names'''# we can easily find out the field names in a named tuple generated class >>> Point2D._fields ('x', 'y') >>> print(Point2D._source) ... # print out what the class is >>> pt = Point2D(10, 20) >>> isinstance(pt, tuple) True# extract named tuple values to a dictionary, by using a instance method. # the keys of the ordered dictionary is in order >>> pt._asdict() OrderedDict([('x', 10), ('y', 20)]) # to make it a normal dictionary >>> dict(pt._asdict()) {'x': 10, 'y': 20}# we can handle it as we deal with the normal tuple x, y = pt x = pt[0] for e in pt: print(e)# in addition, we can also access the data using the field name >>> pt.x # note: you can assign value to it, since it is immutable 10 >>> pt.y 20 # modify named tuples (create a new one) >>> Stock = namedtuple('Stock', 'symbol year month day open high low close') >>> djia = Stock('DJIA', 2018, 1, 25, 26_313, 26_458, 26_260, 26_393) >>> djia Stock(symbol='DJIA', year=2018, month=1, day=25, open=26313, high=26458, low=26260, close=26393)>>> djia = djia._replace(year = 2017, open = 10000) >>> djia Stock(symbol='DJIA', year=2017, month=1, day=25, open=10000, high=26458, low=26260, close=26393)>>> Stock._make(djia[:7] + (1000, )) # _make can take a tuple as parameter Stock(symbol='DJIA', year=2017, month=1, day=25, open=10000, high=26458, low=26260, close=1000)# extend named tuples Stock = namedtuple('Stock', Stock._fields + ('newOne', ))# set default values by using __defaults__ >>> Stock = namedtuple('Stock', 'symbol year month day open high low close') >>> Stock.__new__.__defaults__ = (0, 0, 0) # the last three parameter, read from backwards >>> djia = Stock(1, 2, 3, 4, 5) >>> djia Stock(symbol=1, year=2, month=3, day=4, open=5, high=0, low=0, close=0)# update defaults Stock.__new__.__defaults__ = (-10, -10, -10) >>> djia = Stock(1, 2, 3, 4, 5) >>> djia Stock(symbol=1, year=2, month=3, day=4, open=5, high=-10, low=-10, close=-10)# return multiple values using named tuple # here is to return a random color from random import randint, random from collections import namedtupleColor = namedtuple('Color', 'red green blue alpha')def random_color():red = randint(0, 255)green = randint(0, 255)blue = randint(0, 255)alpha = round(random(), 2) # 精確到兩位小數return Color(red, green, blue, alpha)# transform a dictionary to a nametupledef tuplify_dicts(dicts):keys = {key for dict_ in dicts for key in dict_.keys()}Struct = namedtuple('Struct', sorted(keys), rename=True)Struct.__new__.__defaults__ = (None, ) * len(Struct._fields)return [Struct(**dict_) for dict_ in dicts]data_list = [{'key2': 2, 'key1': 1},{'key1': 3,'key2': 4},{'key1': 5, 'key2': 6, 'key3': 7},{'key2': 100} ]tuple_list = tuplify_dicts(data_list)>>> tuple_list [Struct(key1=1, key2=2, key3=None),Struct(key1=3, key2=4, key3=None),Struct(key1=5, key2=6, key3=7),Struct(key1=None, key2=100, key3=None)]'''If you just read a lot of key-value pairs, you can use namedtuple rather than dictionary due to efficiency. And if your class only has a lot of values and doesn't need mutability, namedtuple is preferred, due to saving space'''

    列表

    判斷列表的連續數字范圍并分塊

    列表中的數字是連續數字(從小到大)

    from itertools import groupby lst = [1,2,3,5,6,7,8,11,12,13,19]func = lambda x: x[1] - x[0] for k, g in groupy(enumerate(lst), func):l1 = [j for i, j in g]if len(l1) > 1:scop = str(min(l1)) + '_' + str(max(l1))else:scop = l1[0]print("連續數字范圍: {}".format(scop))

    里面中的數字是非連續數字即沒有排序,先排序

    lst = [4, 2, 1, 5, 6, 7, 8, 11, 12, 13, 19]for i in range(len(lst)):j = i + 1for j in range(len(lst)):if lst[i] < lst[j]:temp = lst[i]lst[i] = lst[j]lst[j] = temp print("排序后列表:{}".format(lst))

    列表元素的排列組合

    排列

    from itertools import product l = [1, 2, 3] print(list(product(l, l))) # out: [(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)] print(list(product(l, repeat=3))) # out: [(1, 1, 1), (1, 1, 2), (1, 1, 3), (1, 2, 1), (1, 2, 2), (1, 2, 3), (1, 3, 1), (1, 3, 2), (1, 3, 3), (2, 1, 1), (2, 1, 2), (2, 1, 3), (2, 2, 1), (2, 2, 2), (2, 2, 3), (2, 3, 1), (2, 3, 2), (2, 3, 3), (3, 1, 1), (3, 1, 2), (3, 1, 3), (3, 2, 1), (3, 2, 2), (3, 2, 3), (3, 3, 1), (3, 3, 2), (3, 3, 3)]

    組合

    from itertools import combinations print(list(combinations([1,2,3,4,5], 3))) # out: [(1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 3, 4), (1, 3, 5), (1, 4, 5), (2, 3, 4), (2, 3, 5), (2, 4, 5), (3, 4, 5)]

    Map, Filter, Reduce

    Map

    >>> import math >>> def area(r):"""Area of a circle with radius 'r'."""return math.pi * (r**2)>>> radii = [2, 5, 7.1, 0.3, 10] >>> map(area, radii) <map object at 0x112f870f0> >>> list(map(area, radii)) [12.566370614359172, 78.53981633974483, 158.36768566746147, 0.2827433388230814, 314.1592653589793]#convert Celsius to Fahrenheit >>> temps = [("Berlin", 29), ("Beijing", 36), ("New York", 28)] >>> c_to_f = lambda data: (data[0], (9/5)*data[1] + 32) >>> list(map(c_to_f, temps)) [('Berlin', 84.2), ('Beijing', 96.8), ('New York', 82.4)]

    Filter

    In Python, {}, [], (), "", 0, 0.0, 0j, False, None are treated as False.

    #filter the values above the average >>> import statistics >>> data = [1.3, 2.7, 0.8, 4.1, 4.3] >>> avg = statistics.mean(data) >>> avg 2.64 >>> filter(lambda x: x > avg, data) <filter object at 0x112f87780> >>> list(filter(lambda x: x > avg, data)) [2.7, 4.1, 4.3]#remove missing values>>> countries = ["", "China", "Brazil", "", "Germany"] >>> list(filter(None, countries)) ['China', 'Brazil', 'Germany']

    Reduce

    “Use functools.reduce() if you really need it; however, 99% of the time an explicit for loop is more readable.” - Guido van Rossum(Python creator)

    >>> from functools import reduce >>> data = [2, 3, 5, 7, 11] >>> multiplier = lambda x, y: x*y >>> reduce(multiplier, data) # use the product of first two elements to multiply the third, then use the result to multiply the fourth, and so on. 2310

    字典

    幾點注意:

    • for each in 字典名:each為字典中每個項的關鍵字
    • .keys() 返回所有key
    • .values() 返回所有value
    • .Items() 返回字典所有項,以元組的形式
    • .get(key) 獲得該鍵對應的值,如果該key不存在的話,相當于反會了空值,False
    • key in 字典名,存在則返回true,不存在false
    • .clear() 清空字典,被字典賦值的另外的字典也被清空
    • .copy() 拷貝字典 拷貝之后不會被原來的字典影響,區別與直接賦值的方法,dict2=dict1,這個方法在改編dict2時會改變dict1
    • .pop(key) 彈出該鍵的值,并在原字典中刪除
    • .popitem()隨機彈出一個,并在原字典中刪除
    • .setdefault(key, value) 向字典中隨機位置加入一個項
    • 字典1.update(字典2) ,把字典1中與字典2中有相同的key的項的值變成和字典2中一樣
    • .fromkeys((key1, key2, key3), ‘we are the same’)。生成一個新的字典,字典的每個value都是一樣的,等于第二個參數
    • del(字典名[key])可以刪除字典中的該項
    # 函數dict()只有一個參數,所以在輸入許多元組或列表時要在加一個括號都括起來。下面的元組可以換成列表 >>> dict((('F',70), ('i',105), ('s',115))) {'s': 115, 'i': 105, 'F': 70}# 下面的key不要加引號。如果已有這個鍵則重新賦值,沒有則創建一個 >>> dict(key1 = 1, key2 =2, key3=3) {'key2': 2, 'key3': 3, 'key1': 1}# 給字典賦值的另一種方法 >>> MyDict = {} >>> (MyDict['id'],MyDict['name'],MyDict['sex']) = ['212','lala','man'] >>> MyDict {'id': '212', 'sex': 'man', 'name': 'lala'}# 把字典的key和value合并成元組 >>> n = {1: 'a', 2: 'b', 3: 'c'} >>> for x, y in n.items():print((x, y))(1, 'a') (2, 'b') (3, 'c')# 字典推導式 >>> b = {i: i % 2 == 0 for i in range(10)} >>> b {0: True, 1: False, 2: True, 3: False, 4: True, 5: False, 6: True, 7: False, 8: True, 9: False}

    Sort by multiple keys in dictionary

    First, the dictionaries in the list is sorted by the key of “fname”, then based on the result, it is sorted by the key of “lname” partially again.

    from operator import itemgetterusers = [{'fname': 'Bucky', 'lname': 'Roberts'},{'fname': 'Tom', 'lname': 'Roberts'},{'fname': 'Bernie', 'lname': 'Zunks'},{'fname': 'Jenna', 'lname': 'Hayes'},{'fname': 'Sally', 'lname': 'Jones'},{'fname': 'Amanda', 'lname': 'Roberts'},{'fname': 'Tom', 'lname': 'Williams'},{'fname': 'Dean', 'lname': 'Hayes'},{'fname': 'Bernie', 'lname': 'Barbie'},{'fname': 'Tom', 'lname': 'Jones'}, ]for x in sorted(users, key=itemgetter('fname', 'lname')):print(x)# OUTPUT: {'fname': 'Amanda', 'lname': 'Roberts'} {'fname': 'Bernie', 'lname': 'Barbie'} {'fname': 'Bernie', 'lname': 'Zunks'} {'fname': 'Bucky', 'lname': 'Roberts'} {'fname': 'Dean', 'lname': 'Hayes'} {'fname': 'Jenna', 'lname': 'Hayes'} {'fname': 'Sally', 'lname': 'Jones'} {'fname': 'Tom', 'lname': 'Jones'} {'fname': 'Tom', 'lname': 'Roberts'} {'fname': 'Tom', 'lname': 'Williams'}

    Getting key with maximum value in dictionary

    key_with_max_value = max(stats, key=stats.get)

    Update

    用字典b update來更新字典 a,會有兩種情況:

    • 有相同的鍵時:會使用最新的字典 b 中 該 key 對應的 value 值。
    • 有新的鍵時:會直接把字典 b 中的 key、value 加入到 a 中。
    >>> a = {1: 2, 2: 2} >>> b = {1: 1, 3: 3} >>> a.update(b) >>> print(a) {1: 1, 2: 2, 3: 3}

    也可以使用元組更新字典

    d = {'x': 2} d.update(y = 3, z = 0) print(d)# out # {'x': 2, 'y': 3, 'z': 0}

    五、類

    inheritance, Magic, Property Decorator

    class People():def __init__(self, name, age):self.name = nameself.age = agedef __repr__(self):return "People('{}', {})".format(self.name, self.age)def __str__(self):return "I'm {}, and I am {} years old".format(self.name, self.age)people = People("Zhang San", 24) print(people) print(people.__repr__()) # use Magic Method# single inheritance class Male(People):def __init__(self, name, age, hobby):super().__init__(name, age)self.hobby = hobbyclass Play():def __init__(self, game):self.game = game# multiple inheritance class Boy(Male, Play):def __init__(self, name, age, hobby, game, favor_toy):Male.__init__(self, name, age, hobby)Play.__init__(self, game)self.favor_toy = favor_toy# use Property Decorator, which makes a method become a property of the instance@propertydef my_favor_toy(self):return "My favourite toy is " + self.favor_toyboy = Boy('Tim', 24, 'Play video game', 'Street Fighter', 'Lego')print(boy.name) print(boy.hobby) print(boy.game) print(boy.favor_toy) print(boy.my_favor_toy)

    魔法方法總是被雙下劃線包圍,體現在魔法方法總是在適當的時候被自動調用。

    構造器__new__,如果繼承一個不可改變的類如,str,這時必須在初始化之前改變它,__new__就是在__init__實例化之前執行的方法。其中cls可以是任何名字,但是用cls是convention。通過對算數魔法方法的重寫可以自定義任何對象間的算數運算。

    裝飾器Decorators

    If you wrap some function inside another function which adds some functionality to it and executes the wrapped function, you decorated the wrapped function with the outside function. The outside function is a decorator function. A decorator function takes a function as an argument and it returns a closure.

    Decorator can be stacked, if you have two decorator functions, you can just use:

    @decorator1 @decorator2 def func(...):#code

    The order of the decorators does matter and can matter. The above code is equivalent to decorator1(decorator2(func)) which is executed from outside to inside.

    Use a decorator to build a function to calculate Fibonacci Number Series.

    from functools import lru_cache '''lru_cache is a decorator which can cache the result of a function, the parameter maxsize can set the maximum number of items you can cache, the default value is 128, and it's better to be the exponential of 2''' @lru_cache(maxsize=32) def fib(n):print("calculating...{{{0}}}".format(n)) # use double curly brackets {{}} to print out {} return 1 if n <= 2 else fib(n-1) + fib(n-2)# we can also build a caching decorator by ourselves def memoize_fib(fn):cache = dict()def inner(n):if n not in cache:cache[n] = fn(n)return cache[n]return inner@memoize_fib def fib(n):print("calculating...{{{0}}}".format(n))return 1 if n <= 2 else fib(n-1) + fib(n-2)

    If you want to pass a parameter to the decorator function like @memoize_fib(reps), you can wrap the original decorator function with a new outer function, which has a parameter ‘reps’, then return the original decorator when called.
    Any arguments passed to outer can be referenced (as free variables) inside our decorator. We call this outer function a decorator factory(it is a function that creates a new decorator each time it is called).

    Decorator class

    Build a decorator using a class. You can add some parameters in __init__ function, which can act as parameters in decorator factory.

    class Memoize_fib:def __init__(self):self.cache = dict()def __call__(self, fn):def inner(n):if n not in self.cache:self.cache[n] = fn(n)return self.cache[n]return inner@Memoize_fib() def fib(n):print("calculating...{{{0}}}".format(n))return 1 if n <= 2 else fib(n-1) + fib(n-2)

    Decorating classes



    Build a simple debugger for a class by decorator.

    from datetime import datetime, timezonedef info(self):results = []results.append("time: {0}".format(datetime.now(timezone.utc)))results.append("Class: {0}".format(self.__class__.__name__))results.append("id: {0}".format(hex(id(self))))for k, v in vars(self).items():results.append("{0}: {1}".format(k, v))return resultsdef debug_info(cls):cls.debug = inforeturn cls@debug_info class People():def __init__(self, name, age): # __init__ is a method which is called when one instance is created, self is the object it self, it represents the instance createdself.name = name self.age = age # but here it is calling the setter, the initializing step is finished in the setter# in python, use property instead of getter and setter to encapasulate variables. the name of the two following function can be the same as attributes name@propertydef age(self):print("getting")return self._age@age.setterdef age(self, new_age):if new_age <= 0:raise ValueError("Width must be positive.")else:print("setting")self._age = new_age>>> p = People("John",5) >>> p.debug() ['time: 2018-03-31 08:22:51.794910+00:00','Class: People','id: 0x104e1f780','name: John','_age: 5']

    If you have overridden the operators of “==” and “<”, you can realize other operators like “<=”, “>=”, “!=” by decorating a class. The decorator function is in python standard library. As along you have one comparison in the class, the decorator will complete the others.

    from functools import total_ordering from math import sqrt@total_ordering class Point:def __init__(self, x, y):self.x = xself.y = ydef __abs__(self):return sqrt(self.x**2 + self.y**2)def __eq__(self, other):if isinstance(other, Point):return self.x == other.x and self.y == other.yelse:return Falsedef __lt__(self, other):if isinstance(other, Point):return abs(self) < abs(other)else:return NotImplemented>>> p1, p2, p3 = Point(2,3), Point(3,4), Point(3,4) >>> p1 >= p2 False >>> p3 == p2 True

    For the usage of single dispatch generic functions from functools import singledispatch, check the python documentation

    閉包Closures

    # use closure to realize the averager which has the same function of the averager made by using class# use class class Averager:def __init__(self):self.total = 0self.count = 0def add(self, number):self.total += numberself.count += 1return self.total / self.count# use closure def averager():total = 0count = 0def add(number):nonlocal total # 這樣使得add函數里的total和外部函數中的相同,不再是local變量nonlocal counttotal += numbercount += 1return total / countreturn add# make a timer, class from time import perf_counterclass Timer:def __init__(self):self.start = perf_counter()def __call__(self): # call the instance of the class will call the __call__ method directlyreturn perf_counter() - self.start# closure def timer():start = perf_counter()def poll():return perf_counter() - startreturn poll# build a counter which counts the called times of the passed function def counter(fn, counters):cnt = 0def call(*args, **kwargs):nonlocal cntcnt += 1counters[fn.__name__] = cntreturn fn(*args, **kwargs)return calldef add(a, b):return a + bc = dict() add = counter(add, c)>>> add(2,3) 5 >>> add(3,3) 6 >>> c {'add': 2}

    六、程序性能

    程序運行時間

    time

    這兩種方法包含了所有程序的時間,即從運行start到運行end的時間(沒有程序運行也會計算時間)。

    start = time.time() run_func() end = time.time() print(end-start)start = time.clock() run_fun() end = time.clock() print(end-start)

    datetime

    該方法只計算start和end之間CPU運行的程序的時間,和前面對比。

    import datetime starttime = datetime.datetime.now() endtime = datetime.datetime.now() print((endtime - starttime).seconds) # 統計比較長的時間把seconds換成date

    七、I/O讀寫與文件

    open方法

    參數值:

    • ‘r+’ 等價于 rw 可讀可寫
    • ‘w+’ 等價于 wr 可讀可寫
    • ‘a+’ 等價于 ar 可追加可寫

    對應的二進制文件:'rb', 'wb', 'ab', 'rb+', 'wb+', 'ab+'

    r+ Open for reading and writing. The stream is positioned at the beginning of the file.

    a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The output is appended to the end of the file.

    file = r'./test.txt' with open(file, 'a+') as f:f.write("some text" + "\n")

    Remove newline ‘\n’ remark of each line

    temp = file_.read().splitlines() # or temp = [line[:-1] for line in file_] # or temp = line.strip()

    遞歸遍歷目錄

    os.walk(top[, topdown=True[, οnerrοr=None[, followlinks=False]]])
    根目錄下的每一個文件夾(包含它自己), 產生3-元組 (dirpath, dirnames, filenames)【文件夾路徑, 文件夾名字, 文件名】

    • topdown 可選,為True或者沒有指定, 一個目錄的的3-元組將比它的任何子文件夾的3-元組先產生
      (目錄自上而下)。如果topdown為 False, 一個目錄的3-元組將比它的任何子文件夾的3-元組后產生 (目錄自下而上)
    • onerror 可選,是一個函數; 它調用時有一個參數, 一個OSError實例。報告這錯誤后,繼續walk,或者拋出exception終止walk。
    • followlinks 設置為true,則通過軟鏈接訪問目錄。
    import os # 打印所有文件路徑, cur_dir表示file_list里的當前文件所在的路徑 g = os.walk("/path/to/dir") for cur_dir, dir_list, file_list in g: for file_name in file_list: print(os.path.join(cur_dir, file_name) )# 打印所有文件夾路徑 for cur_dir, dir_list, file_list in g: for dir_name in dir_list:print(os.path.join(cur_dir, dir_name))

    Concatenate files

    filenames = [file1.txt, file2.txt, ...] with open('path/to/output/file', 'w') as outfile:for fname in filenames:with open(fname) as infile:for line in infile:outfile.write(line) import shutil with open('output_file.txt', 'wb') as wfd:for f in ['seg1.txt', 'seg2.txt', 'seg3.txt']:with open(f, 'rb') as fd:shutil.copyfileobj(fd, wfd)

    CSV文件

    把二維列表寫進csv文件

    import csv list_of_lists = [[1,2,3],[4,5,6],[7,8,9]] with open("out.csv","w") as f:writer = csv.writer(f, delimiter=" ") # 設置分隔符,如逗號、空格等writer.writerows(list_of_lists) # 最后輸出格式為二維表格,each sublist is a row.

    批量拼接(concatenate)CSV文件

    此處代碼為收集一個大文件夾的各個子文件夾內的CSV文件,并且拼接成一個大的CSV文件,并且加入了過濾空文件,其他類型文件的功能

    import pandas as pd import glob import osfiles_folder=[] week = 1sub_folders = glob.glob('/PATH/*')for folder in sub_folders:all_files = []files = os.listdir(folder)for file in files:if file[-3:] == 'csv':all_files.append(folder +'/' + file)files_folder.append(all_files)for folder in files_folder:tables = []for file in folder:if os.path.getsize(file) > 0:table = pd.read_csv(file)tables.append(table)result = pd.concat(tables, ignore_index=True)for row in range(result.shape[0]):if str(result.loc[row, 'items']).find(',') == -1:result = result.drop([row])result.to_csv('/PATH/merge_week{}.csv'.format(week), index=False)week += 1

    JSON文件

    Json data is almost identical to a python dictionary and it is shorter than XML.

    >>>import json >>>json_file = open("/path/to/jsonfile", "r", encoding="utf-8") >>>loadedJson = json.load(json_file) # json_file can be a string >>>json_file.close()#you can access the content by key like >>>loadedJson["keyName"]#convert a dictionary to a json string >>>dic = {"name": "yi", "gender": "male"} >>>json.dumps(dic)#write it to a file >>>file = open("/path/to/store/jsonfile", "w", encoding="utf-8") >>>json.dump(dic, file) file.close()

    Pickle

    The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy.

    The following types can be pickled:

    • None, True, and False
    • integers, floating point numbers, complex numbers
    • strings, bytes, bytearrays
    • tuples, lists, sets, and dictionaries containing only picklable objects
    • functions defined at the top level of a module (using def, not lambda)
    • built-in functions defined at the top level of a module
    • classes that are defined at the top level of a module
    • instances of such classes whose __dict__ or the result of calling __getstate__() is picklable
    import pickle# To store a list with open('outfile', 'wb') as fp:pickle.dump(itemlist, fp)# To read it back: with open ('outfile', 'rb') as fp:itemlist = pickle.load(fp)# To store a dictionary import pickle# An arbitrary collection of objects supported by pickle. data = {'a': [1, 2.0, 3, 4+6j],'b': ("character string", b"byte string"),'c': {None, True, False} }with open('data.pickle', 'wb') as f:# Pickle the 'data' dictionary using the highest protocol available.pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)# To read it back: with open('data.pickle', 'rb') as f:# The protocol version used is detected automatically, so we do not# have to specify it.data = pickle.load(f)

    八、系統操作

    文件

    設定連續且不重復的文件夾名,易于日志管理

    最簡單的辦法就是用創建時間區分,即timestamp

    import datetime now = datetime.utcnow().strftime("%Y%m%d%H%M%S") root_logdir = "/PATH/logs" logdir = "{}/run-{}".format(root_logdir, now) # 之后就用logdir在loop中命名文件夾就行了

    recursively find absolute path of certain file

    from pathlib import Path for filename in Path('src').rglob('*.c'):print(filename)

    創建目錄/文件夾

    # old method import os if not os.path.exists(directory):os.makedirs(directory)# new method # recursively creates the directory and does not raise an # exception if the directory already exists. If you don't need # or want the parents to be created, skip the parents argument. from pathlib import Path Path("/my/directory").mkdir(parents=True, exist_ok=True)

    其他Path類的功能

    from pathlib import Path p = Path(file) p.cwd() # 獲取當前路徑,Python程序所在路徑,而不是指定文件的當前路徑 p.stat() # 獲取當前文件的信息 p.exists() # 判斷當前路徑是否是文件或者文件夾 p.is_dir() # 判斷該路徑是否是文件夾 p.is_file() # 判斷該路徑是否是文件 p.iterdir() #當path為文件夾時,通過yield產生path文件夾下的所有文件、文件夾路徑的迭代器 p.rename(target) # 當target是string時,重命名文件或文件夾;當target是Path時,重命名并移動文件或文件夾 p.replace(target) # 重命名當前文件或文件夾,如果target所指示的文件或文件夾已存在,則覆蓋原文件 p.parent(),p.parents() # parent獲取path的上級路徑,parents獲取path的所有上級路徑 p.is_absolute() # 判斷path是否是絕對路徑 p.rmdir() # 當path為空文件夾的時候,刪除該文件夾 p.suffix # 獲取path文件后綴 p.match(pattern) # 判斷path是否滿足pattern

    文件運行路徑

    os.getcwd() 輸出起始執行目錄,就是在哪個目錄運行python命令行,就輸出哪個目錄的絕對路徑

    sys.path[0] 輸出被初始執行的腳本的所在目錄,比如python ./test/test.py,就輸出test.py所在的目錄的絕對路徑

    sys.argv[0] 輸出第一個參數,就是運行文件本身 ./test/test.py

    os.path.split(os.path.realpath(__file__))[0] 輸出運行該命令的的python文件的所在的目錄的絕對路徑,該命令所在的文件的目錄不同,輸出的絕對路徑就不同

    九、異常

    Assert斷言

    當assert這個關鍵字后面的條件為假的時候,程序自動崩潰并拋出AssertionError的異常。

    >>> assert 3>4 Traceback (most recent call last):File "<pyshell#100>", line 1, in <module>assert 3>4 AssertionError# assert <condition>,<error message> >>> assert 2 + 2 == 5, "Houston we've got a problem" Traceback (most recent call last):File "<pyshell#105>", line 1, in <module>assert 2 + 2 == 5, "Houston we've got a problem" AssertionError: Houston we've got a problem

    一般來說我們可以用assert在程序中插入檢查點,當需要確保程序中的某個條件一定為真才能讓程序正常工作的話,assert就非常有用。(Assert statements are a convenient way to insert debugging assertions into a program)

    def avg(marks):assert len(marks) != 0,"List is empty."return sum(marks)/len(marks)mark2 = [55,88,78,90,79] print("Average of mark2:",avg(mark2))mark1 = [] print("Average of mark1:",avg(mark1))# output: # Average of mark2: 78.0 # AssertionError: List is empty.

    十、模塊Module

    模塊是包含所有定義函數和變量的文件,后綴為.py。使用之前要用import引入。os模塊,會幫助你在不同的操作系統環境下與文件,目錄交互。

    Package包

    Packages are special modules. Packages can contain modules and packages called sub-packages. If a module is a package, it must have a value set for __path__.

    The reason to use packages is that they have the ability to break code up into smaller chunks, make our code:

    • easier to write
    • easier to test and debug
    • easier to read/understand
    • easier to document

    After you have imported a module, you can easily see if that module is a package by inspecting the __path__ attribute (empty -> module, non-empty -> package). Packages represent a hierarchy of modules/packages, just like books are broken down into chapters, sections, paragraphs, etc. E.g.

    • pack1.mod1
    • pack1.pack1_1.mod1_1

    On a file system we therefore have to use directories for packages. The directory name becomes the package name.

    To define a package in our file system, we must:

    • create a directory whose name will be the package name
    • create a file called __init__.py inside that directory

    That __init__.py file is what tells Python that the directory is a package as opposed to a standard directory

    Pip

    pip install -r requirements.txt 安裝目錄下的requirements.txt中的python包

    第三方庫

    scipy

    讀取.mat文件

    import scipy.io as scio m = scio.loadmat("/path/to/your/.mat") # m是字典格式,通過下面查看有哪些key m.keys()# 保存python字典到mat文件 scio.savemat(dataNew, {'A':data['A']})

    numpy

    讀取存儲

    Numpy也可以存儲Python的字典

    embedding_dict = {1:222,2:333} np.save("embedding_dict.npy", embedding_dict) embedding_dict=np.load("embedding_dict.npy")

    總結

    以上是生活随笔為你收集整理的Python3常用代码块汇总的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    久久精彩免费视频 | 丁香在线 | 亚洲成人免费观看 | 91精品一区国产高清在线gif | 天天综合成人网 | 在线观看aaa | 中文字幕亚洲情99在线 | 国产看片网站 | 久草精品视频在线看网站免费 | 久久不射网站 | 996久久国产精品线观看 | 成人av片在线观看 | 国产特黄色片 | 国内一区二区视频 | 欧美日韩午夜 | 国产精品久久久久影院日本 | 91在线国产观看 | 91视频首页 | 看av免费网站 | 亚洲乱码国产乱码精品天美传媒 | 久久a级片 | 美女福利视频 | 亚洲专区在线播放 | 91麻豆产精品久久久久久 | 最近免费在线观看 | 日韩精品久久久 | 午夜精品一区二区三区在线观看 | 国产精品中文字幕在线播放 | 天天天天色综合 | 中日韩免费视频 | 黄色免费观看 | 一级片色播影院 | 亚洲黄色a| 五月天,com| 中文字幕频道 | 一区二区观看 | 国产一区二区在线影院 | 精品一区二区在线观看 | 国产精品国产三级国产aⅴ无密码 | 色综合天天射 | 能在线观看的日韩av | 成年人电影免费看 | av一级片网站 | 成人国产精品 | 免费看wwwwwwwwwww的视频 久久久久久99精品 91中文字幕视频 | 丝袜美女视频网站 | 久久99精品久久久久久秒播蜜臀 | 黄色成人影视 | 97在线观看免费观看高清 | 久久久999免费视频 日韩网站在线 | 六月婷婷久香在线视频 | 九九视频免费观看视频精品 | 天天亚洲综合 | 999久久久免费精品国产 | 欧美日韩久久 | 久久精品96 | 久久人人爽人人人人片 | 国产精品一区二区视频 | 久久日韩精品 | 91九色porny蝌蚪视频 | 中文字幕第 | 国产日韩欧美在线影视 | 婷婷在线网 | 中文字幕在线观看网 | 99久久99久国产黄毛片 | 在线只有精品 | 中文字幕人成不卡一区 | 欧美二区在线播放 | 一区二区三区视频在线 | 啪啪肉肉污av国网站 | 中文字幕无吗 | 成人黄色在线视频 | 日本精品中文字幕 | 亚洲综合在线播放 | 精品国产一区二区久久 | 亚洲国产成人精品在线 | 久久久久久久久久毛片 | 丝袜美腿av | 日韩免费区 | 黄网站色视频 | 欧美性粗大hdvideo | 免费特级黄色片 | 日韩中文字幕在线 | 国产伦精品一区二区三区照片91 | 激情片av | 91中文在线视频 | 国产精品视频免费在线观看 | 国产精品福利av | 亚洲成人午夜在线 | 日韩欧美精品一区 | 久久久久久久久久久成人 | 99午夜| 91av在线免费观看 | 国产成视频在线观看 | 久久久久国产精品免费网站 | 精品一区电影 | 成人午夜精品久久久久久久3d | 天天干,天天射,天天操,天天摸 | 狠狠干网址| 狠狠色丁香婷婷综合久小说久 | 国产91精品一区二区绿帽 | 日韩在线 一区二区 | 免费电影播放 | 色99导航 | 婷婷伊人五月 | 美女久久99 | 91丨九色丨首页 | 免费在线观看av片 | 久久99视频精品 | 一区二区三区四区影院 | 国产高清视频免费最新在线 | 黄污网 | 久久a热6| 国产亚洲免费观看 | 久久se视频| av中文字幕在线电影 | 久久一区二区三区国产精品 | 日精品在线观看 | 91免费高清观看 | 欧美 日韩 成人 | 麻豆网站免费观看 | 亚洲一级片 | 国产精品无av码在线观看 | 少妇高潮流白浆在线观看 | 狠狠操狠狠操 | 久久久国产日韩 | 日韩免费在线视频 | 美女视频久久久 | 99精品免费在线 | 国产成人在线免费观看 | 96久久 | 999一区二区三区 | 又爽又黄又刺激的视频 | 99久久婷婷国产一区二区三区 | 69国产在线观看 | 欧美 亚洲 另类 激情 另类 | 韩国av在线 | 免费开视频 | 国产123区在线观看 国产精品麻豆91 | 99c视频高清免费观看 | 最新日本中文字幕 | 四虎永久国产精品 | 九九热视频在线播放 | 97精品伊人 | 91精品在线视频观看 | 国产高清在线视频 | 久久视频免费在线观看 | 欧美精品xxx| 精品欧美日韩 | 天天综合色网 | 久久精品99国产精品亚洲最刺激 | 久草视频在线免费 | 久久美女免费视频 | 粉嫩av一区二区三区四区在线观看 | 久久精品老司机 | 国产欧美综合视频 | 中文字幕日本在线观看 | 91香蕉视频好色先生 | 久久久久久久久久久高潮一区二区 | 中文字幕在线色 | 亚洲六月丁香色婷婷综合久久 | 五月天久久久久 | 国产精品综合久久久 | 欧美日韩不卡一区二区 | 五月天久久狠狠 | 色免费在线 | 黄色网址国产 | 婷婷福利影院 | 婷婷看片 | 成人在线免费观看视视频 | 日韩精品久久中文字幕 | 亚洲免费在线观看视频 | 伊人亚洲综合 | 国产 日韩 中文字幕 | 成人在线观看av | 综合色在线观看 | 午夜视频欧美 | 在线视频亚洲 | 精品久久久久久久久久 | 狠狠操精品 | 国产黄色精品在线 | 1000部国产精品成人观看 | 久久久免费网站 | 亚州精品国产 | 亚洲成人影音 | 中文字幕人成人 | 国产在线成人 | 91亚洲国产 | 91激情 | 欧美aⅴ在线观看 | 久久久久麻豆 | 成人a视频 | 色天天中文 | 欧美极品少妇xxxxⅹ欧美极品少妇xxxx亚洲精品 | 深夜福利视频一区二区 | 国产精品国产毛片 | 日韩视频免费看 | 日韩av一区二区在线影视 | 一级a毛片高清视频 | a级片久久久 | 天天色.com | 99免费视频 | 最新av中文字幕 | 亚洲成a人片在线观看网站口工 | 天天干天天弄 | 久久私人影院 | 久久公开视频 | www.亚洲精品视频 | 日日爽天天 | 日韩免费在线看 | 亚洲精品在线视频观看 | 欧美乱码精品一区二区 | 久精品视频 | 中文字幕 欧美性 | 不卡的av中文字幕 | av在线播放快速免费阴 | 欧美日韩亚洲第一页 | 五月天天av| 久久精品网站免费观看 | 91av中文| 成人观看| 91在线永久 | 日本bbbb摸bbbb| 欧美福利网站 | 综合久久精品 | 中文字幕日韩电影 | 国产亚洲精品成人av久久影院 | 在线免费观看黄色 | 亚洲在线视频观看 | 五月天色站 | 国产大陆亚洲精品国产 | 久久久久久久久久久久电影 | 久久黄色精品视频 | 91九色视频在线观看 | 国语麻豆| 婷婷5月色 | 久久精品国产免费看久久精品 | 免费看一级黄色大全 | 日韩高清三区 | 久久国产精品一区二区三区 | 日韩一级电影在线 | 黄色的网站免费看 | 国产亚洲资源 | 久久成人国产 | 91精品久| 日韩av免费一区 | 深爱激情开心 | 日韩免费中文字幕 | 天天草夜夜| 中文字幕在线看视频 | 特级毛片在线免费观看 | 亚洲手机天堂 | av在线8 | 婷婷丁香激情 | 国产精品v欧美精品 | 91精品久久久久久久久久久久久 | 天天干天天干天天色 | 日韩伦理一区二区三区av在线 | 婷婷综合网 | 日韩视频一区二区在线观看 | 日本福利视频在线 | www色网站| 国产二区精品 | 激情五月婷婷丁香 | 日韩精品一区二区三区水蜜桃 | 日日干天天插 | 免费国产在线精品 | 午夜黄网 | 国产自在线| 综合激情伊人 | 欧美日韩p片 | 日韩av影片在线观看 | 国产亚洲综合在线 | 欧美日韩视频观看 | 亚洲狠狠婷婷综合久久久 | 丁香六月天婷婷 | 色婷婷a| 在线观看久久久久久 | 国产精品毛片久久久久久久久久99999999 | 九九久久电影 | 色婷婷激情网 | 亚洲欧美日韩国产 | 中文字幕av有码 | 一级免费av| 午夜私人影院久久久久 | 在线免费观看不卡av | 在线亚洲精品 | 精品久久影院 | 亚洲视频1区2区 | 天天摸天天操天天舔 | 97成人精品视频在线观看 | 久久久亚洲网站 | 亚洲欧美日韩一级 | 狠狠操天天干 | 亚洲v精品 | 日韩三级免费 | 亚洲成人资源 | 国产91大片 | 免费福利片 | 天天操天天操天天操 | 久青草影院 | 久久经典国产 | www欧美日韩 | 欧美在线aa | 精品国产成人在线 | 欧美韩日视频 | 国产黄色精品在线 | 在线观看av中文字幕 | 精品国产一区在线观看 | 999电影免费在线观看2020 | 久久女教师 | 亚洲欧美国产精品久久久久 | a黄在线观看 | 婷婷福利影院 | 亚洲综合激情小说 | 中文字幕在线播放日韩 | 日日精品 | 美女网站黄在线观看 | 久久久999免费视频 日韩网站在线 | 欧美福利在线播放 | 极品美女被弄高潮视频网站 | 夜夜躁狠狠躁日日躁视频黑人 | 欧美三级在线播放 | 日韩免费在线观看视频 | 天天干天天操天天爱 | 91免费观看视频在线 | 国内精品99 | 一区二区视频电影在线观看 | 久久九九精品 | 久久久久北条麻妃免费看 | 国产精品日韩久久久久 | 91麻豆精品国产91久久久无需广告 | 国产一级二级三级在线观看 | 中文字幕高清av | 亚洲成人av一区二区 | 91亚洲精品久久久蜜桃借种 | 色婷婷狠狠五月综合天色拍 | av电影在线免费观看 | 久久久久久久久久久综合 | 伊甸园永久入口www 99热 精品在线 | 欧美另类网站 | 99热最新网址 | 黄色免费国产 | 久久不见久久见免费影院 | 成人久久18免费网站图片 | 99在线热播精品免费99热 | 日韩av在线小说 | 久久久精品欧美一区二区免费 | 99在线免费视频观看 | 国产精品成人国产乱 | 狠狠躁18三区二区一区ai明星 | 亚洲国产无 | 91入口在线观看 | 香蕉视频久久 | 91视频在线播放视频 | 国产成人av一区二区三区在线观看 | 808电影 | 少妇bbbb| 91伊人久久大香线蕉蜜芽人口 | av一级久久 | 国产一级片播放 | 国产高清区 | 黄色软件网站在线观看 | 久久伦理| 欧美日韩高清在线观看 | 日韩一区正在播放 | 亚洲精品在线观看的 | 六月丁香婷 | 日韩3区| 五月天天天操 | 亚洲综合色激情五月 | 天天做日日做天天爽视频免费 | 国产精品都在这里 | 国产成人高清 | 日韩av女优视频 | 9色在线视频| 午夜av一区二区三区 | 97av免费视频| 99精品欧美一区二区蜜桃免费 | 久久视频在线免费观看 | 激情综合色综合久久 | 九色自拍视频 | 亚欧日韩成人h片 | 免费a视频在线观看 | 国产一卡二卡四卡国 | 特级西西444www大精品视频免费看 | 欧美日韩国产综合一区二区 | 国产在线久草 | 国产永久免费高清在线观看视频 | 五月婷婷在线播放 | 日本三级在线观看中文字 | 欧美专区亚洲专区 | 日本中文字幕在线电影 | 国产精品免费在线播放 | 国产精品一区二区三区在线看 | 免费视频在线观看网站 | 久久男人免费视频 | 91爱爱电影 | 在线天堂中文在线资源网 | 毛片久久久 | 欧美性生活一级片 | 天天操天天干天天干 | 亚洲精品国产精品国 | 青春草免费视频 | 天天干,夜夜爽 | 亚洲视频在线视频 | 91精品在线视频 | 国产午夜三级一区二区三桃花影视 | 九九免费在线观看 | 成人天堂网| 日本精品久久久一区二区三区 | 欧美日韩视频在线观看免费 | 夜夜爽天天爽 | 久热爱 | 成人黄色av网站 | 日韩mv欧美mv国产精品 | 亚洲视频专区在线 | 伊人天天干 | 久产久精国产品 | 成人av在线影视 | 日韩理论片在线 | 久草av在线播放 | 一区二区伦理 | 探花视频在线观看+在线播放 | 少妇性色午夜淫片aaaze | 天天躁天天操 | 精品二区久久 | 在线成人av | av免费观看网站 | 91精品国产一区二区在线观看 | 中文字幕中文字幕在线中文字幕三区 | 日韩精品一区二区三区在线播放 | 久久久久欠精品国产毛片国产毛生 | 69xx视频 | 国产亚洲精品福利 | 精品一区欧美 | 精品国产一区二区三区男人吃奶 | 91精品老司机久久一区啪 | 久久在线一区 | 免费色视频在线 | 激情网五月婷婷 | 91精品国产高清自在线观看 | 日韩久久一区二区 | 毛片网站免费在线观看 | 91精品第一页 | 91影视成人 | 美女在线免费视频 | 91久久在线观看 | av短片在线观看 | 亚洲理论在线观看电影 | 亚洲视频第一页 | 黄色性av | 美腿丝袜一区二区三区 | 人人射人人澡 | 国产免费嫩草影院 | 国产美女视频免费观看的网站 | 成人av中文字幕在线观看 | 欧美一级视频在线观看 | 中文字幕在线专区 | 久久久久五月天 | 高清av网站 | 999国内精品永久免费视频 | 亚洲涩综合| 色婷婷综合在线 | 国内精品久久久久 | 五月婷婷爱 | 欧美日韩国产在线一区 | 国产精品av免费 | 日韩av手机在线观看 | 不卡av在线 | 九九亚洲精品 | 国产精品女人久久久 | 国产精品福利久久久 | 天天夜夜亚洲 | 精品二区久久 | 亚洲资源在线观看 | 久久永久免费 | 国产精品黄色 | 能在线看的av | 天天色天天爱天天射综合 | 最近日韩中文字幕中文 | 草 免费视频 | 色婷婷激情电影 | 国产一区二区三区网站 | 久久久久久毛片精品免费不卡 | 国产一区在线视频 | 精品久久久影院 | 亚洲精品国产第一综合99久久 | 精品在线免费视频 | 国内精品视频一区二区三区八戒 | 久久久久久久久久国产精品 | 国产99久久久欧美黑人 | 97国产在线视频 | www.人人草| 波多野结衣在线观看一区二区三区 | 国产不卡av在线 | 精品夜夜嗨av一区二区三区 | 精品国产欧美一区二区三区不卡 | 日本三级香港三级人妇99 | 国产亚洲免费的视频看 | 免费在线播放视频 | 在线久草视频 | 久久视频在线观看中文字幕 | 国产精品日韩久久久久 | 国产成人av电影在线观看 | 国产精品久久久久一区二区三区 | 久热av | 天天干夜夜爱 | 亚洲精品乱码久久久久久蜜桃动漫 | 在线三级中文 | 久久综合九色综合欧美狠狠 | 婷婷成人亚洲综合国产xv88 | av福利网址导航大全 | 国产精品久久av | www.色国产| 国内外成人在线视频 | 亚洲伊人网在线观看 | 久久国产精品视频免费看 | 亚洲日韩欧美视频 | 丁香综合网 | 色搞搞 | 超级碰99 | 国产黄色片免费 | 狠狠躁日日躁 | 亚洲精选在线观看 | 青草草在线视频 | 99re视频在线观看 | 久久精品香蕉 | 激情网站| 四虎永久免费在线观看 | 欧美精品少妇xxxxx喷水 | a在线免费 | 中文字幕在线影视资源 | 一区二区三区精品久久久 | 99视频一区二区 | 亚洲成人黄 | 免费又黄又爽的视频 | 中文字幕在线观看完整版 | 国产精品视频区 | 国产综合91| 亚洲精品综合在线 | 国产精品久久久久久吹潮天美传媒 | 日日摸日日爽 | 久久极品 | 96国产精品视频 | 成人看片 | 精品国产一二三四区 | 免费在线观看av | 国产欧美在线一区二区三区 | 国产日韩中文字幕在线 | 日日草av| 久艹视频免费观看 | 久久精品一区八戒影视 | 日本黄色免费大片 | 又色又爽又激情的59视频 | 色综合天天做天天爱 | 久久视频这里只有精品 | 国产高清在线观看 | 久操视频在线播放 | www欧美色 | 97精品国产97久久久久久粉红 | 国产九色91| 日韩欧美视频在线 | 在线成人免费电影 | 五月天亚洲精品 | 亚洲精品女人 | a在线免费观看视频 | 久草在线视频免赞 | 精品一区二三区 | 天天爽夜夜爽精品视频婷婷 | 99国产精品 | 亚洲电影av在线 | 97人人澡人人爽人人模亚洲 | 涩涩网站在线 | 午夜精品久久久 | 丁香婷婷成人 | 18做爰免费视频网站 | 色婷婷狠 | 亚洲成人家庭影院 | 麻豆小视频在线观看 | 国产人成免费视频 | 一区二区三区免费网站 | 国产在线视频在线观看 | 欧美另类交人妖 | 最新国产精品拍自在线播放 | 五月开心网 | 亚洲国产精品人久久电影 | 99久久激情| 国产999视频在线观看 | 国产精品久久久久久久久毛片 | 国产伦理一区二区三区 | 亚洲 欧美 国产 va在线影院 | 国产资源免费 | 欧洲av在线| 天天操欧美 | 国产女人40精品一区毛片视频 | 久久亚洲美女 | 伊人影院在线观看 | 日本 在线 视频 中文 有码 | 国产成人精品久久久久蜜臀 | 欧美亚洲国产日韩 | 亚洲视频www| 精品视频中文字幕 | 美女黄色网在线播放 | 日本女人逼 | 国产亚洲精品久久久网站好莱 | 97在线观看免费高清完整版在线观看 | 国内精品久久久精品电影院 | 国产精品毛片一区二区在线 | 午夜美女视频 | 中文字幕在线观看一区二区三区 | 中文字幕在线播放视频 | 91久久丝袜国产露脸动漫 | 激情婷婷av| 精品久久久免费视频 | 狠狠操综合 | 青青久草在线 | 亚洲理论片在线观看 | 狠狠亚洲 | 中文字幕在线观看视频一区 | 午夜精品一区二区三区免费视频 | 日本久久不卡视频 | 五月天综合网站 | 国产精品黄色 | 免费高清在线视频一区· | 玖玖玖国产精品 | 国产精品久久久久av免费 | 亚洲精品一区二区在线观看 | 一区二区三区www | 国产日韩精品一区二区 | 欧美在线视频一区二区三区 | avwww在线| 色婷婷色 | 九九热精品视频在线观看 | 国产美女视频免费 | 久久成人在线 | 亚洲狠狠干 | av品善网 | 国产精品女同一区二区三区久久夜 | 国产专区视频在线观看 | 国产一区在线不卡 | 香蕉免费在线 | 夜夜夜夜猛噜噜噜噜噜初音未来 | 国产91粉嫩白浆在线观看 | 久久爱资源网 | 成人久久视频 | 日本大尺码专区mv | 久久国产系列 | 午夜久久网站 | 久久热亚洲 | 97视频在线免费播放 | 中文一区在线观看 | 亚洲自拍偷拍色图 | 日韩av在线一区二区 | 久久午夜精品视频 | 亚洲自拍偷拍色图 | 91激情| 国产精品网址在线观看 | 美女天天操 | 成人av资源在线 | 狠狠色丁香婷婷综合橹88 | 欧美日韩国产在线观看 | 日本三级不卡 | 天天干天天操人体 | 日本动漫做毛片一区二区 | 精品主播网红福利资源观看 | 亚洲精品影院在线观看 | 日韩在线观看的 | 人人超碰免费 | 久操中文字幕在线观看 | 欧美午夜理伦三级在线观看 | 美女久久久久久 | 99久久er热在这里只有精品66 | 国产裸体无遮挡 | 久草免费在线观看 | 中文字幕文字幕一区二区 | 一本一道久久a久久综合蜜桃 | 成人国产精品久久久久久亚洲 | 免费看一及片 | 美女视频一区 | 亚洲精品乱码久久久久久蜜桃欧美 | 人人草人人草 | 2019免费中文字幕 | 一区二区三区四区五区在线视频 | 久久久 激情 | 97精品视频在线播放 | 黄色免费av | 国产精品视频永久免费播放 | 五月香视频在线观看 | 国产精品 亚洲精品 | 国产精品自产拍在线观看网站 | 在线国产一区二区三区 | 国产日韩精品欧美 | 免费在线观看亚洲视频 | 国产黄色片一级三级 | 色国产在线 | 国产91精品看黄网站 | 在线天堂中文在线资源网 | 国产精品中文字幕在线观看 | 黄色三级免费观看 | 久久视频免费在线 | av免费电影在线 | 射九九| 国产高清专区 | 国产黄色美女 | 色婷婷狠狠18 | 欧美日韩国产在线精品 | 天堂入口网站 | 国产在线一区二区 | 97超碰在线免费 | 久久久久久久久久久久电影 | 最新国产视频 | 国产精品美女久久 | 国产精品久久久久久久久久直播 | 欧美一级在线 | 精品久久久免费视频 | 久久婷婷综合激情 | 欧美在线视频第一页 | 97福利| 日韩视频一二三区 | 人人澡av| 在线观看免费成人 | 久久婷婷五月综合色丁香 | 免费在线激情电影 | 9999免费视频 | 亚洲日本精品视频 | 欧美粗又大 | 久久爱992xxoo| 九九久久国产 | 亚洲欧美精品一区二区 | 亚洲精品在线免费看 | 久久成人黄色 | 在线观影网站 | 五月天综合网 | 丁香激情五月 | 91精品免费看 | 探花视频免费在线观看 | 日韩av高清| 久久久不卡影院 | 激情婷婷在线观看 | 久久99亚洲精品久久久久 | 亚洲最大av网 | 一区二区精品视频 | 欧美国产日韩在线视频 | 成人一区二区在线观看 | 激情影音 | 毛片网站免费在线观看 | 国产精品自在线拍国产 | 超碰官网 | 粉嫩av一区二区三区四区在线观看 | 国产精品手机在线播放 | 激情视频一区二区三区 | 97国产在线观看 | 天天干中文字幕 | 精品久久美女 | 国产精品综合在线 | 91看成人 | 91插插插免费视频 | 国产高清成人 | 男女视频久久久 | 97香蕉超级碰碰久久免费软件 | 精品在线观看一区二区 | 欧美黑人巨大xxxxx | 亚洲免费不卡 | 福利二区视频 | 欧美视频网址 | 国内精品久久久久久久影视麻豆 | 天天爱天天射 | 婷婷中文字幕在线观看 | 国产成人一区二区三区 | 国产一级片免费观看 | 欧美韩国日本在线观看 | 高清av网站| 成人a视频片观看免费 | 国产一级免费观看 | www.色就是色| 欧美少妇的秘密 | 天天操人| 一级电影免费在线观看 | 亚洲国产一区二区精品专区 | 亚洲片在线资源 | 激情网站网址 | 激情综合网色播五月 | 激情视频一区二区三区 | 2018亚洲男人天堂 | 人人爽人人澡 | 一级精品视频在线观看宜春院 | 久久久久免费精品视频 | 99久久夜色精品国产亚洲 | 韩国在线一区二区 | 亚洲欧美激情精品一区二区 | 亚洲在线 | 成人一级 | 免费观看一级成人毛片 | 中文字幕 国产精品 | 日韩中文字幕电影 | 欧美日韩一区二区在线观看 | 免费a网站| 精品久久久免费视频 | 免费在线国产 | 亚洲欧洲日韩在线观看 | 99999精品 | 免费开视频 | 天天综合天天做 | 国产综合91 | 婷婷福利影院 | 午夜美女福利 | 久久久精品国产一区二区 | 色视频在线 | 五月婷婷六月丁香 | 日韩中文字幕视频在线观看 | 91九色蝌蚪在线 | 毛片网站免费在线观看 | 在线免费视频 你懂得 | 欧美一进一出抽搐大尺度视频 | 国产精品aⅴ | 国产精品不卡av | 日韩欧美综合 | 色五婷婷 | 国产午夜精品在线 | 国内精品久久久久久中文字幕 | 久久久穴 | 国产精品一区二区三区在线看 | 在线观看的av网站 | ww视频在线观看 | 国产丝袜网站 | 欧美精品久久久久久久久久久 | 亚洲四虎在线 | 午夜精品久久久久久久99水蜜桃 | 一区精品在线 | 久久全国免费视频 | 少妇高潮流白浆在线观看 | 成人啊 v | 99视频在线免费播放 | 日韩三级在线观看 | 久草在线电影网 | 日本黄色免费电影网站 | 91九色在线播放 | 三级黄色在线 | 午夜精品久久久久久久99无限制 | 国产精品淫 | 久久婷亚洲五月一区天天躁 | 在线观看视频在线观看 | 国产偷在线 | 精品视频99| 久久久久高清毛片一级 | 国产精品丝袜 | 午夜电影一区 | 久久九九网站 | 97在线超碰 | 大胆欧美gogo免费视频一二区 | 91九色视频导航 | 久久色中文字幕 | 久久久久福利视频 | 婷婷伊人综合 | 欧美狠狠操 | av在线免费播放 | 亚洲综合射 | 国产精品免费久久久久久久久久中文 | 综合色影院 | 亚洲成人第一区 | 又黄又刺激的视频 | 最新av在线网站 | 日韩一级黄色av | 国产精品女同一区二区三区久久夜 | 国产不卡一二三区 | 亚洲成色 | 亚洲最新av在线网站 | 久久96 | 91精品电影| 97日日 | 天天草天天操 | a级国产乱理伦片在线播放 久久久久国产精品一区 | 黄色免费网站大全 | 欧美日韩一区二区视频在线观看 | 亚洲综合在线观看视频 | 国产高清视频免费最新在线 | 国产精品在线看 | 91丨九色丨丝袜 | 天天插天天 | 91av观看 | 天天操天天曰 | 国产一区视频在线播放 | 天天拍天天干 | 色综合久久五月天 | 国产精品高潮呻吟久久av无 | 黄色大全免费网站 | 亚洲精品啊啊啊 | 97视频一区| 欧美久久久久久 | 亚洲欧洲成人 | 精品久久毛片 | 人人插人人费 | 免费福利在线观看 | 亚洲精品乱码久久久久v最新版 | 午夜国产福利在线 | 久久天天躁狠狠躁夜夜不卡公司 | 人人干人人添 | 欧美日韩国产在线一区 | 黄色网大全| 免费福利小视频 | 免费的黄色av | 97色se | 色婷婷www | 一区二区三高清 | 成人免费在线看片 | 色网站中文字幕 | 久久国产一区二区 | 欧美精品国产综合久久 | 美女视频a美女大全免费下载蜜臀 | 中文字幕av一区二区三区四区 | www.人人干| 国产精品久久久999 国产91九色视频 | 三级小视频在线观看 | 亚洲 欧美 国产 va在线影院 | 欧美极品久久 | 激情婷婷色 | 天堂av网址 | 日本精品一区二区三区在线播放视频 | 亚洲最新av网址 | 欧美最猛性xxxxx亚洲精品 | 九九九视频精品 | 国产专区一 | 国内精品久久久久国产 | 国产日韩欧美精品在线观看 | 日本特黄特色aaa大片免费 | 国产一区二区精品久久91 | 一本色道久久综合亚洲二区三区 | 成人黄色大片在线免费观看 | 天天色天天射天天干 | 免费视频 你懂的 | 开心激情网五月天 | 免费av网站在线看 | 黄色三级视频片 | 五月婷婷影视 | 国产精品一区二区在线免费观看 | 欧美激情精品久久久久久 | 蜜臀精品久久久久久蜜臀 | 丝袜+亚洲+另类+欧美+变态 | 91精品一区二区三区久久久久久 | 五月天久久久 | 亚洲人xxx| 免费av片在线 | 成人a在线 | 成人a免费看| 综合网五月天 | 国产精品福利久久久 | 亚洲精品视频免费在线 | 国产成人精品一区二区三区在线观看 | 午夜国产福利视频 | 欧美,日韩 | av在线免费不卡 | 国产成人高清 | 操操操日日日干干干 | 久久婷婷国产色一区二区三区 | 99久久婷婷国产 | 99色视频在线 | 天天爽夜夜爽人人爽曰av | 日韩欧美专区 | 国产999精品久久久久久麻豆 | 国产手机在线播放 | 日韩一区二区三区观看 | 国产私拍在线 | 最近免费中文视频 | 一 级 黄 色 片免费看的 | 一区在线播放 | 国产精品美女久久久久久久 | 久久视频精品在线 | 国产精品视频免费看 | 天天艹天天 | 日韩在线网 | 国产精品6| 免费开视频 | 天天干,狠狠干 | 97av视频| 成人a视频在线观看 | 日本一区二区三区免费观看 | 一区二区中文字幕在线 | 天天色天天射综合网 | 日日操夜夜操狠狠操 | 91成人午夜 | 日韩高清精品免费观看 | 人人躁 | 欧美一级欧美一级 | 久久久久久久久久久久久久免费看 | 国产视频观看 | 久久国产成人午夜av影院宅 | 中文字幕久久精品 | 黄色福利网站 | 久久久在线免费观看 | 欧美亚洲成人xxx | 狂野欧美激情性xxxx | 在线免费色视频 | 久久天天躁 | 久久精品区 | 久章草在线观看 | 97人人澡人人爽人人模亚洲 | 精品久久久久一区二区国产 |