Python筆記

1、局部變量->全局變量
def func():
a=1
print(a)
global b
b=2
print(b)

func()
print(b)

global b=2,這樣寫是錯(cuò)誤的憎乙。

2氮昧、# [python 從外部獲取傳入的參數(shù)]
(https://www.cnblogs.com/juan-F/p/9707467.html)
import sys #引入模塊
str = sys.argv[1]
print str

Python中如何獲得當(dāng)前所執(zhí)行的腳本的名字:
sys.argv[0]是傳入的參數(shù),通過解析佩研,可以得到當(dāng)前python腳本的文件名铜犬。

python獲取函數(shù)參數(shù)個(gè)數(shù)的方法(https://blog.csdn.net/Wu_Victor/article/details/84334814
def sum(a,b):
return(a+b)

print(sum.code.co_argcount)

輸出的函數(shù)參數(shù)個(gè)數(shù)

print(sum.code.co_varnames)

('a', 'b')

這里會(huì)輸出函數(shù)用到的所有變量名,不只是參數(shù)名

import sys模塊:
len(sys.argv)參數(shù)個(gè)數(shù)
sys.argv[0]程序名
sys.argv[1]第一個(gè)參數(shù)
sys.argv[1:]是所有參數(shù)

3轻庆、python 中time.time()獲取到的是從1970-1-1 00:00:00 到現(xiàn)在的秒數(shù)(小數(shù)位還有6位)癣猾。

需要獲取毫秒數(shù)的時(shí)候:
import time
int(time.time()*1000)

4、訪問字典里的值
把相應(yīng)的鍵放入熟悉的方括弧余爆,如下實(shí)例:

!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print "dict['Name']: ", dict['Name']

7纷宇、創(chuàng)建多層目錄
import os
dirs = '/Users/joseph/work/python/'
if not os.path.exists(dirs):
os.makedirs(dirs)

判斷是否是文件:
os.path.isfile("abc")

8、 sleep()方法
time.sleep(1) # 休眠1秒

9蛾方、bytes轉(zhuǎn)字符串
b=b'\xe9\x80\x86\xe7\x81\xab'
string=str(b,'utf-8')
print(string)

10像捶、# [python讀文件指定行的數(shù)據(jù)]
import linecache
print linecache.getline('url.txt',2)

11上陕、# 常用終止python程序方法
方法1:采用sys.exit(0)正常終止程序,從圖中可以看到拓春,程序終止后shell運(yùn)行不受影響释簿。
方法2:采用os._exit(0)關(guān)閉整個(gè)shell,從圖中看到硼莽,調(diào)用sys._exit(0)后整個(gè)shell都重啟了(RESTART Shell)庶溶。

12、os.system(cmd)的返回值懂鸵。
如果執(zhí)行成功偏螺,那么會(huì)返回0,表示命令執(zhí)行成功匆光。

coding = utf-8

import os
path = '/root/Downloads/dir/'

if os.system("ls {}".format(path)) == 0:
print("return 0 represent success!")

13套像、# python調(diào)用sqlite
import sqlite3

cx = sqlite3.connect("text");

創(chuàng)建游標(biāo)

cu = cx.cursor()
cu.execute("create table test (id integer,name varchar(10),nickname blob )")

14、獲取環(huán)境變量字典
import os

env_dist = os.environ # environ是在os.py中定義的一個(gè)dict environ = {}
print env_dist.get('JAVA_HOME')

15终息、pycharm 一鍵 快速 批量 修改變量名 快捷鍵
快捷鍵為:Ctrl+Shift+Alt+J

16夺巩、一般用于Windows下
file_path = os.path.split(path) #分割出目錄與文件
lists = file_path[1].split('.') #分割出文件與文件擴(kuò)展名
file_ext = lists[-1] #取出后綴名(列表切片操作)

17、將hive采幌、sqoop等命令的執(zhí)行輸出寫入日志
import subprocess #Popen

proc = subprocess.Popen(medusaCMD, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
for line in iter(proc.stdout.readline, 'b'):
print line
if not subprocess.Popen.poll(proc) is None:
if line == "":
break
proc.stdout.close()

18劲够、join()函數(shù)

對(duì)元組進(jìn)行操作(分別使用' ' 、' - '與':'作為分隔符)

c=('1','2','3','4','5')
' '.join(c)
1 2 3 4 5
'-'.join(c)
1-2-3-4-5
':'.join(c)
1:2:3:4:5

19休傍、# Python中’main’模塊的作用
https://www.cnblogs.com/crazyrunning/p/6904658.html

22征绎、Python3 * 和 ** 運(yùn)算符(函數(shù)傳參)
https://blog.csdn.net/yilovexing/article/details/80577510

23、# [python 字符串替換]
將一個(gè)字符串中的每個(gè)空格替換成“%20”磨取。例如人柿,當(dāng)字符串為 s=‘We Are Happy’.則經(jīng)過替換之后的字符串為We%20Are%20Happy。

方法一:s.replace(' ','%20')

方法二:用正則表達(dá)式
import re
s = 'We Are Happy' p = re.compile(' ')
replace = p.sub('%20',s)
print(replace)</pre>

24忙厌、Python批量執(zhí)行文件夾下SQL文件
http://www.reibang.com/p/0604d9dbcafd

25凫岖、# python 中 open與with open 的區(qū)別

使用with創(chuàng)建運(yùn)行時(shí)環(huán)境

with open('xxx.text', encoding='utf-8') as file:
file_content = file.read()
file.seek(0)
file_ten_characters = file.read(10)
print(file_content)
print(file_ten_characters)
#執(zhí)行完with中的代碼后自動(dòng)退出運(yùn)行時(shí)環(huán)境

for line in f.readlines():
print( line.strip() )

26、# Python列表中去重的多種方法

l1 = [1,4,4,2,3,4,5,6,1]
l2 = list(set(l1))
print(l2) # [1, 2, 3, 4, 5, 6]

27逢净、python 寫文件
https://www.cnblogs.com/miaomiaokaixin/p/11505949.html

with open(path,"a",encoding="utf-8") as f3:
f3.write("young girl")

29哥放、python3 判斷文件目錄是否存在
import os

判斷文件是否存在(絕對(duì)/相對(duì)路徑)。

print(os.path.exists("downloadFailure.txt"))

判斷目錄是否存在(絕對(duì)/相對(duì)路徑)爹土。

print(os.path.exists("project_origin"))

30甥雕、創(chuàng)建目錄
os.makedir(log_path)

31、# python中獲取執(zhí)行腳本路徑方法
import sys

print(sys.path)
print(sys.path[0]) #獲取執(zhí)行腳本目錄絕對(duì)路徑

sys.argv[0]:獲取腳本執(zhí)行本身路徑

33胀茵、移除(刪除)文件及文件夾處理
https://blog.csdn.net/qq_33733970/article/details/83376888
shutil.rmtree() 表示遞歸刪除文件夾下的所有子文件夾和子文件社露。

import shutil,os
if os.path.exists(os.path.join(bizimage_filepath, image_name)):
//移除文件
os.remove(os.path.join(bizimage_filepath, image_name))
//移除帶文件的文件夾
shutil.rmtree(bizimage_filepath)

34、用Python批量復(fù)制文件
https://www.sohu.com/a/277948273_571478
import shutil
copyfile(source, target)
copy(source, target)

35琼娘、switch/case
https://blog.csdn.net/l460133921/article/details/74892476
def num_to_string(num):
numbers = {
0 : "zero",
1 : "one",
2 : "two",
3 : "three"
}

return numbers.get(num, None)

36峭弟、大小寫轉(zhuǎn)化
print(str.upper()) # 把所有字符中的小寫字母轉(zhuǎn)換成大寫字母
print(str.lower()) # 把所有字符中的大寫字母轉(zhuǎn)換成小寫字母

37附鸽、exit(0)和exit(1)的用法和區(qū)別
exit(0):無錯(cuò)誤退出
exit(1):有錯(cuò)誤退出

38、 strip() 方法用于移除字符串頭尾指定的字符(默認(rèn)為空格或換行符)或字符序列
str = "00000003210Runoob01230000000";
print str.strip( '0' ); # 去除首尾字符 0

str2 = " Runoob "; # 去除首尾空格
print str2.strip();

以上實(shí)例輸出結(jié)果如下:
3210Runoob0123
Runoob

39瞒瘸、三目運(yùn)算
a=(x if (x>y) else y)
print(a if (a>z) else z)

40坷备、pyCharm中添加方法注釋
https://blog.csdn.net/dkjkls/article/details/88933950
File -> Settings -> Tools -> Python Integrated Tools -> Docstrings -> Docstring format

41、python離線安裝openpyxl
python setup.py install

42挨务、name == 'main' 到底是什么意思
https://blog.csdn.net/longintchar/article/details/87120496

43击你、爬蟲--正則表達(dá)式(https://www.cnblogs.com/zhuifeng-mayi/p/9652331.html

image.png

44、# python怎么用一個(gè)print換行輸出多個(gè)變量
print(n,f,s1,s2,s3,s4,sep='\n')

45谎柄、操作mysql
https://blog.csdn.net/yushupan/article/details/85061143

46丁侄、使用executemany對(duì)數(shù)據(jù)進(jìn)行批量插入(https://www.jb51.net/article/108314.htm

coding:utf8

conn = MySQLdb.connect(host = “l(fā)ocalhost”, user = “root”, passwd = “123456”, db = “myDB”)
cursor = conn.cursor()
sql = “insert into myTable (created_day,name,count) values(%s,%s,%s) ON DUPLICATE KEY UPDATE count=count+values(count)”
args=[("2012-08-27","name1",100),("2012-08-27","name1",200),("2012-08-27","name2",300)]
try:
cursor.executemany(sql, args)
except Exception as e:
print0(“執(zhí)行MySQL: %s 時(shí)出錯(cuò):%s” % (sql, e))
finally:
  cursor.close()
  conn.commit()
  conn.close()

47、Python腳本開頭
https://www.jb51.net/article/149613.htm

48朝巫、python – 如何獲取網(wǎng)址中最后一個(gè)斜杠之后的所有內(nèi)容鸿摇?(http://www.voidcn.com/article/p-olecydro-bsr.html
URL: http://www.test.com/page/page/12345
returns: 12345

url.rsplit('/', 1)[-1]

49、Python3 三目運(yùn)算符
a if x else b
如果 x 為 True劈猿,返回 a拙吉;否則返回 b

50、python--瀏覽器url編解碼中文轉(zhuǎn)換(https://blog.csdn.net/hubingshabi/article/details/101626670
from urllib.parse import quote, unquote
print(unquote('%E4%B8%AD%E5%9B%BD'))
print(quote('農(nóng)業(yè)'))

51揪荣、BeautifulSoup常見的解析器(https://blog.csdn.net/smile_Shujie/article/details/92781804

圖片.png

52筷黔、# python爬蟲beautifulsoup查找定位Select用法
https://www.cnblogs.com/vipchenwei/p/7807860.html
https://www.cnblogs.com/cttcarrotsgarden/p/10770205.html

.find() 和 .findAll() 用法 ( https://www.136.la/shida/show-30052.html

53、# xpath定位方法詳解

54仗颈、# Python中字符串String去除出換行符和空格的問題(\n,\r)
在python中存在繼承了 回車符\r 和 換行符\n 兩種標(biāo)記

aa.replace('\n', '').replace('\r', '') 去掉 aa字符內(nèi)所有的 回車符和換行符

aa.string.replace(' ', '') 去掉 aa字符內(nèi)所有的 空格

aa.strip() 只能夠去除aa字符串首尾的空格佛舱,不能夠去除中間的空格

55、判斷列表是否為空(https://www.cnblogs.com/shenxiaolin/p/12546678.html
list_temp = []
if list_temp: # 存在值即為真
print(True)
else: # list_temp是空的
print(False)

57挨决、json 代碼標(biāo)準(zhǔn)化(https://tool.oschina.net/codeformat/css

58请祖、字符串轉(zhuǎn)浮點(diǎn)型數(shù)字
x = 123.456
y = float(x)
print(y)

59、# python遍歷字典的四種方法
for key,value in a.items():
print(key+':'+value)

a:1
b:2
c:3

60脖祈、Python之字典添加元素的幾種方法(https://www.jb51.net/article/196873.htm

使用update()方法肆捕,參數(shù)為字典對(duì)象
book_dict.update({"country": "china"})

61、Python中產(chǎn)生隨機(jī)數(shù)(https://blog.csdn.net/zq476668643/article/details/95219453
產(chǎn)生0到1之間的浮點(diǎn)數(shù): random.random()
產(chǎn)生n---m之間的浮點(diǎn)數(shù): random.uniform(1.1,5.4)

62盖高、Python取整——向上取整慎陵、向下取整(https://blog.csdn.net/weixin_41712499/article/details/85208928
向上取整:math.ceil()
import math

math.ceil(-0.5)
>>> 0
 
math.ceil(-0.9)
>>> 0
 
math.ceil(0.3)
>>> 1

63、python怎么保留小數(shù)點(diǎn)位數(shù)(https://jingyan.baidu.com/article/fea4511aa40df6b7bb9125c6.html
a=1.2222345
a=('%.2f' % a)
print(a)

64喻奥、if 語句數(shù)字邏輯判斷(https://blog.csdn.net/qq_31931797/article/details/96734318
python支持10>=a>=0席纽,不用像java中還要寫成a >= 0 and a <= 10

66、用Python爬取芒果TV映凳、騰訊視頻胆筒、B站邮破、愛奇藝诈豌、知乎仆救、微博這幾大平臺(tái)的彈幕、評(píng)論矫渔,看這一篇就夠了彤蔽!
https://cloud.tencent.com/developer/article/1872409

67、Python注釋之TODO注釋(https://blog.csdn.net/u014571489/article/details/82943036

68庙洼、徹底搞懂Python異常處理:try-except-else-finally(https://blog.csdn.net/weixin_42152811/article/details/115189076

無論有無異常顿痪,finally代碼段一定會(huì)被執(zhí)行
若有異常,則執(zhí)行except代碼段
若無異常且無return油够,則執(zhí)行else代碼段
若無異常且有return蚁袭, try代碼段中有return 語句, 則else代碼段不會(huì)被執(zhí)行
若無異常且有return石咬, try代碼段沒有return語句揩悄,則else代碼段會(huì)執(zhí)行

70、# python-----實(shí)現(xiàn)print不換行
print('Hello',end='')

71鬼悠、range設(shè)置步長(zhǎng)
for i in range(10, 100, 10):
print(i)

72删性、Python format 格式化函數(shù)(https://www.runoob.com/python/att-string-format.html)

實(shí)例

"{} {}".format("hello", "world") # 不設(shè)置指定位置,按默認(rèn)順序
'hello world'

"{0} {1}".format("hello", "world") # 設(shè)置指定位置
'hello world'

"{1} {0} {1}".format("hello", "world") # 設(shè)置指定位置
'world hello world'

73焕窝、列表轉(zhuǎn)字符串 # python list 與 String 互相轉(zhuǎn)換
str0 = '127.0.0.1'
list0 = str0.split('.')
print(list0)

str1 = '#'.join(list0)
print(str1)

74蹬挺、# Python一個(gè)文件調(diào)用另外一個(gè)文件的方法
https://blog.csdn.net/sinat_38682860/article/details/109103445

from MainProgramWB import PublicMethod

75、Python中的 if name == "main"到底是個(gè)啥意思它掂?(https://blog.csdn.net/weixin_35684521/article/details/81396434

得出一個(gè)非常實(shí)用的結(jié)論: 如果模塊是被直接運(yùn)行的巴帮,則代碼塊被運(yùn)行,如果模塊被import群发,則代碼塊不被運(yùn)行晰韵。

76、local variable referenced before assignment 原因及解決辦法(https://blog.csdn.net/sinat_40304087/article/details/115701595
不要在函數(shù)內(nèi)部改變?nèi)肿兞康闹凳旒耍绻_實(shí)想改變?nèi)肿兞康闹担ㄒ詀為例)雪猪,那么需要在函數(shù)內(nèi)部首先聲明,即加上global a這一行代碼起愈。

77只恨、關(guān)于import datetime和from datetime import datetime同時(shí)添加報(bào)錯(cuò)(https://blog.csdn.net/feiyang5260/article/details/87831088

同時(shí)添加兩個(gè)引用會(huì)導(dǎo)致由于有兩個(gè)同名datetime模塊,調(diào)用datetime模塊函數(shù)時(shí)程序不知道調(diào)用的是哪一個(gè)而報(bào)錯(cuò)抬虽,from datetime import datetime是import datetime的子模塊

解決方案:
將from datetime import datetime刪除官觅,需要引用該子模塊函數(shù)時(shí),利用import datetime來調(diào)用阐污,即datetime.datetime.函數(shù)名()

78休涤、This inspection detects situations when list creation could be rewritten with list literal.(https://blog.csdn.net/u014418725/article/details/89145380
在使用pycharm IDE的時(shí)候,聲明空List,出現(xiàn)如題警告功氨,雖然并不影響運(yùn)行序苏,但是看起來比較煩人。故嘗試消除

point_collection = list()
point_collection.append(point_list)

79捷凄、# Python模擬登錄的幾種方法
https://blog.csdn.net/weixin_45651841/article/details/107358424

from selenium import webdriver
import time

chrome_driver = r"C:\ProgramData\Anaconda3_new\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_driver)

driver = webdriver.Chrome()

driver.get('https://weibo.com/login.php')
driver.manage().window().maximize()
time.sleep(10)
user = driver.find_element_by_xpath('//[@id="loginname"]')
user.clear()
user.send_keys('953923621@qq.com')
passwd = driver.find_element_by_xpath('//
[@id="pl_login_form"]/div/div[3]/div[2]/div/input')
passwd.clear()
passwd.send_keys('bud,99Lax')

login = driver.find_element_by_css_selector('#pl_login_form > div > div:nth-child(3) > div.info_list.login_btn > a')

login.click()

time.sleep(1) # 如果有驗(yàn)證碼忱详,給出輸入驗(yàn)證碼的時(shí)間

driver.get_cookies()

80、# Beautiful Soup 如何獲取到href
for item in goods_list:
print('https:' + item.attrs['href'])

81跺涤、python 從list中隨機(jī)取值(https://blog.csdn.net/weixin_39791387/article/details/84958436
import random
list1 = ['佛山', '南寧', '北海', '杭州', '南昌', '廈門', '溫州']
a = random.choice(list1)
print(a)

82匈睁、Python split()方法(https://www.runoob.com/python/att-string-split.html
str3 = str2.rsplit('}', 1)

print(str3)

txt = "Google#Runoob#Taobao#Facebook"

第二個(gè)參數(shù)為 1,返回兩個(gè)參數(shù)列表

x = txt.split("#", 1)

print x

83桶错、隨機(jī)打亂列表(https://blog.csdn.net/wyounger/article/details/106265336
第一種方法:
x = ['aa', 'bb', 'cc', 'dd', 'ee']
random.shuffle(x)
print(x)

第二種方法(轉(zhuǎn)為set):
word_list = ['波司登', '竹葉青茶', '涪陵榨菜', '奧康', '雅迪', '飛鶴', '云集', '安踏', '幡然', 'GMMCYY', '羅德梅科', 'aymelon', 'prevadaza', 'TWININGS', 'TWG', 'Harney & Sons', 'Dilmah', 'Tetley', '魚泉', '六必居', '飯掃光', '味聚特', '紅蜻蜓', '蜘蛛王', '愛瑪', '臺(tái)鈴', '新日', '惠氏',
'贊美臣', '雅培', '伊利', '君樂寶', '李寧', '特步', '鴻星爾克']
for item in set(word_list):
print(item)

84航唆、列表倒序(https://www.runoob.com/python/att-list-reverse.html

aList = [123, 'xyz', 'zara', 'abc', 'xyz']

aList.reverse()
print "List : ", aList

85、指定范圍產(chǎn)生隨機(jī)數(shù)(https://blog.csdn.net/weixin_42503456/article/details/113709505
1院刁、random.random( )

random.random( )佛点,用于生成范圍在[0, 1)之間的隨機(jī)實(shí)數(shù)。

2黎比、random.uniform(a, b)

random.uniform(a, b)超营,用于生成一個(gè)指定范圍[a, b]內(nèi)的隨機(jī)符點(diǎn)數(shù)。

86阅虫、# python 字符串是否包含某個(gè)子字符串
if str1 in str2:
  包含的話演闭,True

87、Python中如何打印列表中每個(gè)元素的下標(biāo)颓帝?(https://www.zhihu.com/question/429208384
for i,item in enumerate(nodes):
video_id=item['nodes'][0]['nodes'][0]['data']['videoId']
url='https://v.youku.com/v_show/id_'+video_id+'.html'
print(i,url)

88米碰、遍歷set(https://www.cnblogs.com/xiaoit/p/4045563.html
weekdays = set(['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'])

for d in weekdays:
print (d)

89、# python腳本傳遞參數(shù)
import sys

print(sys.argv[0]) #sys.argv[0] 類似于shell中的$0,但不是腳本名稱购城,而是腳本的路徑
print(sys.argv[1]) #sys.argv[1] 表示傳入的第一個(gè)參數(shù)吕座,既 hello

90、# python 讀取TXT文檔內(nèi)容 轉(zhuǎn)換為字典
with open("yester.txt","r",encoding="utf-8") as f:
user_dict={}
for userline in f:
userline=str(userline).replace('\n','')
user_dict[userline.split(' ',1)[0]]=userline.split(' ',1)[1]

91瘪板、python:讀寫文件判斷一行是否為空(https://blog.csdn.net/lwgkzl/article/details/82148054

92吴趴、python中自帶的計(jì)數(shù)器(https://blog.csdn.net/weixin_44076384/article/details/86777624)
from collections import Counter

txt = 'from collections import Counter'
print(type(Counter))
print(Counter(txt))
print(Counter(txt).most_common())
print(Counter(txt).most_common(2))
print(Counter(txt.split()))

93、# python字符串格式化方法%s和format函數(shù)

print("my name is %s and i am %d years old" %("xiaoming",18)

94侮攀、python中ravel()用法(https://blog.csdn.net/yunfeather/article/details/106316811
a.ravel() #ravel()方法將[數(shù)組]維度拉成一維數(shù)組

Numpy 中的 ravel() 和 flatten()

95锣枝、fillna()函數(shù)詳解(https://blog.csdn.net/lien0906/article/details/105483342/)
inplace參數(shù)的取值:True、False

True:直接修改原對(duì)象

False:創(chuàng)建一個(gè)副本兰英,修改副本撇叁,原對(duì)象不變(缺省默認(rèn))

96、Python列表去重(https://www.cnblogs.com/huturen/p/15103531.html
old_list = [2, 3, 4, 5, 1, 2, 3]
new_list = list(set(old_list))
new_list.sort(key=old_list.index)
print(new_list) # 保留順序:[2, 3, 4, 5, 1]

97畦贸、logging


image.png

添加輸出一些公共默認(rèn)信息


image.png

每天生成一個(gè)日志文件


image.png
image.png
image.png
image.png
image.png
image.png
image.png

image.png
image.png
image.png

98陨闹、Python中subplots_adjust函數(shù)的說明(https://blog.csdn.net/lty_sky/article/details/104589415/)

99、文件讀取路徑
file_path = os.path.abspath('data/testSet.txt')

100、pip 和pip3區(qū)別(https://blog.csdn.net/qq_40584960/article/details/86082019)
python 有python2和python3的區(qū)別
那么pip也有pip和pip3的區(qū)別
大概是這樣的
1趋厉、pip是python的包管理工具泡一,pip和pip3版本不同,都位于Scripts\目錄下:
2觅廓、如果系統(tǒng)中只安裝了Python2,那么就只能使用pip涵但。
3杈绸、如果系統(tǒng)中只安裝了Python3,那么既可以使用pip也可以使用pip3矮瘟,二者是等價(jià)的瞳脓。
4、如果系統(tǒng)中同時(shí)安裝了Python2和Python3澈侠,則pip默認(rèn)給Python2用劫侧,pip3指定給Python3用。
5哨啃、重要:虛擬環(huán)境中烧栋,若只存在一個(gè)python版本,可以認(rèn)為在用系統(tǒng)中pip和pip3命令都是相同的

101拳球、如何安裝python_speech_features(https://blog.csdn.net/just_h/article/details/81265559?utm_source=blogxgwz4

pip3 install python_speech_features

102审姓、python中shutil.copy()的用法(https://blog.csdn.net/weixin_46471983/article/details/121990552
shutil.copy(src, dst)是為了復(fù)制文件內(nèi)容且不包含元數(shù)據(jù)從src到dst,
dst必須是完整的文件路徑文件名

注意:如果src和dst是同一個(gè)文件祝峻,就會(huì)引發(fā)錯(cuò)誤魔吐,dst必須是可寫的,否則將引發(fā)錯(cuò)誤莱找,如果dst已經(jīng)存在酬姆,就會(huì)被替換

https://blog.csdn.net/qq_25360769/article/details/80023656

103、python的yield方法_python中的yield詳解(https://blog.csdn.net/weixin_30444573/article/details/112963765

調(diào)用函數(shù)并不會(huì)執(zhí)行語句

def foo():
print('Starting.....')
while True:
res = yield 4
print("res:", res)

下面調(diào)用函數(shù)并沒有執(zhí)行奥溺,可以先將后面的語句注釋掉

逐行運(yùn)行代碼觀察效果

g = foo()
print("第一次調(diào)用執(zhí)行結(jié)果:")
print(next(g))
print("" * 100)
print("第二次調(diào)用執(zhí)行結(jié)果:")
print(next(g))
print("
" * 100)第一次調(diào)用執(zhí)行結(jié)果:
Starting.....

4


第二次調(diào)用執(zhí)行結(jié)果:

res: None

4


104辞色、切片操作(https://www.bilibili.com/video/BV16541197nw?vd_source=36b6f1ba2243b2e495afeec952d78e6c

image.png

105、zip() 函數(shù)(http://c.biancheng.net/view/2237.html)
my_list = [11,12,13]
my_tuple = (21,22,23)

print([x for x in zip(my_list,my_tuple)])

my_dic = {31:2,32:4,33:5}
my_set = {41,42,43,44}

print([x for x in zip(my_dic)])

my_pychar = "python"
my_shechar = "shell"

print([x for x in zip(my_pychar,my_shechar)])

程序執(zhí)行結(jié)果為:
[(11, 21), (12, 22), (13, 23)]
[(31,), (32,), (33,)]
[('p', 's'), ('y', 'h'), ('t', 'e'), ('h', 'l'), ('o', 'l')]

106浮定、divmod()(https://blog.csdn.net/yizhishuixiong/article/details/105237838
計(jì)算 a 除以 b 的商和余數(shù)淫僻,并返回一個(gè)包含商和余數(shù)的元組

image.png

107、python里apply用法_Python apply函數(shù)的用法(https://blog.csdn.net/weixin_36313588/article/details/113993242

108壶唤、args和*kwargs是什么意思(https://blog.csdn.net/qingsi11/article/details/112285969

總的來說饶囚,args代表任何多個(gè)無名參數(shù),返回的是元組擂啥;kwargs表示關(guān)鍵字參數(shù)遗锣,所有傳入的key=value,返回字典;
def test(a,
args,**kwargs):
print(a)
print(args)
print(kwargs)
test(1,3,5,7,c='2',d=4)

1
(3, 5, 7)
{‘c’: ‘2’, ‘d’: 4}

109躲撰、python裝飾器詳解(https://blog.csdn.net/weixin_44992737/article/details/125868592
裝飾器本質(zhì)上是一個(gè)Python函數(shù)(其實(shí)就是閉包)针贬,它可以讓其他函數(shù)在不需要做任何代碼變動(dòng)的前提下增加額外功能,裝飾器的返回值也是一個(gè)函數(shù)對(duì)象拢蛋。裝飾器用于有以下場(chǎng)景桦他,比如:插入日志、性能測(cè)試谆棱、事務(wù)處理快压、緩存、權(quán)限校驗(yàn)等場(chǎng)景

image.png

110垃瞧、python中的eval函數(shù)和map函數(shù)(https://blog.csdn.net/qq_45599904/article/details/108175308)
for i in FocusList:
print(i,22)
print(type(i))

      FocusList = map(eval, FocusList)
        for i in FocusList:
            print(i)
            print(type(i))

0 22
<class 'str'>
1 22
<class 'str'>
2 22
<class 'str'>
3 22
<class 'str'>
0
<class 'int'>
1
<class 'int'>
2
<class 'int'>
3
<class 'int'>

111蔫劣、

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市个从,隨后出現(xiàn)的幾起案子脉幢,更是在濱河造成了極大的恐慌,老刑警劉巖嗦锐,帶你破解...
    沈念sama閱讀 218,858評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件嫌松,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡奕污,警方通過查閱死者的電腦和手機(jī)豆瘫,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來菊值,“玉大人外驱,你說我怎么就攤上這事∧逯希” “怎么了昵宇?”我有些...
    開封第一講書人閱讀 165,282評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)儿子。 經(jīng)常有香客問我瓦哎,道長(zhǎng),這世上最難降的妖魔是什么柔逼? 我笑而不...
    開封第一講書人閱讀 58,842評(píng)論 1 295
  • 正文 為了忘掉前任蒋譬,我火速辦了婚禮,結(jié)果婚禮上愉适,老公的妹妹穿的比我還像新娘犯助。我一直安慰自己,他們只是感情好维咸,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,857評(píng)論 6 392
  • 文/花漫 我一把揭開白布剂买。 她就那樣靜靜地躺著惠爽,像睡著了一般。 火紅的嫁衣襯著肌膚如雪瞬哼。 梳的紋絲不亂的頭發(fā)上婚肆,一...
    開封第一講書人閱讀 51,679評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音坐慰,去河邊找鬼较性。 笑死,一個(gè)胖子當(dāng)著我的面吹牛结胀,可吹牛的內(nèi)容都是我干的赞咙。 我是一名探鬼主播,決...
    沈念sama閱讀 40,406評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼把跨,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了沼死?” 一聲冷哼從身側(cè)響起着逐,我...
    開封第一講書人閱讀 39,311評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎意蛀,沒想到半個(gè)月后耸别,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,767評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡县钥,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評(píng)論 3 336
  • 正文 我和宋清朗相戀三年秀姐,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片若贮。...
    茶點(diǎn)故事閱讀 40,090評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡省有,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出谴麦,到底是詐尸還是另有隱情蠢沿,我是刑警寧澤,帶...
    沈念sama閱讀 35,785評(píng)論 5 346
  • 正文 年R本政府宣布匾效,位于F島的核電站舷蟀,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏面哼。R本人自食惡果不足惜野宜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,420評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望魔策。 院中可真熱鬧匈子,春花似錦、人聲如沸闯袒。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至原茅,卻和暖如春吭历,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背擂橘。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評(píng)論 1 271
  • 我被黑心中介騙來泰國打工晌区, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人通贞。 一個(gè)月前我還...
    沈念sama閱讀 48,298評(píng)論 3 372
  • 正文 我出身青樓朗若,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國和親昌罩。 傳聞我的和親對(duì)象是個(gè)殘疾皇子哭懈,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,033評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容