日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

测试自动化学习7

發(fā)布時(shí)間:2023/12/20 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 测试自动化学习7 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

python讀取Excel

import xlrdbook = xlrd.open_workbook('my_user-bak.xls') sheet = book.sheet_by_index(0) print(sheet.row_values(0)) # 某一行數(shù)據(jù) print(sheet.col_values(0)) # 某一列數(shù)據(jù) print(sheet.cell(0,0).value) # 某個(gè)單元格的數(shù)據(jù) print(sheet.cell(1,2).value) # 某個(gè)單元格的數(shù)據(jù) print(sheet.nrows) # 總共多少行 print(sheet.ncols) # 總共多少列print('----') for i in range(sheet.nrows): # 打印所有行print(sheet.row_values(i))

?

python修改Excel內(nèi)容

import xlrd from xlutils import copy""" 1.用xlrd模塊打開Excel 2.用xlutils模塊里面的copy復(fù)制一份 3.獲取到sheet頁(yè) 4.修改 """book = xlrd.open_workbook('students.xls') new_book = copy.copy(book) sheet = new_book.get_sheet(0) sheetr = book.sheet_by_index(0) sheet.write(0,6,'年齡階段')for i in range(1, sheetr.nrows):if sheetr.cell(i,3).value < 18:sheet.write(i, 6, '騷年')elif 18 <= sheetr.cell(i,3).value < 30:sheet.write(i, 6, '成年人開車')else:sheet.write(i, 6, '老當(dāng)益壯')new_book.save('students.xls')

?

python發(fā)郵件

import yagmailuser = 'xxx@qq.com' passwd = 'xxxxx' # 在系統(tǒng)賬戶設(shè)置開啟授權(quán)碼訪問,不可直接使用qq密碼登錄 smtp_host = 'smtp.qq.com'mail = yagmail.SMTP(user=user,password=passwd,host=smtp_host,smtp_ssl=True) # 連上郵箱 mail.send(to='@qq.com',cc='xxxaa@qq.com',subject='好好睡',contents='多吃多吃',attachments=['test.py', '寫日志.py']) # 多個(gè)人傳入list

?

操作Redis,可以使用rdm圖形軟件操作輔助觀察,也可以直接用python操作

import redishost = '127.0.0.1' passwd = 'xxxxx'r = redis.Redis(host=host, password=passwd, db=15, decode_responses=True) # 選擇第幾個(gè)db,一般0-15 # decode_responses=True,返回的就不是bytes類型了,就是字符串了# string類型 # r.set('session_id_dd','s1243sdfsdfs') #新增和修改 # # result = r.get('session_id_') # # r.delete('session_id_dd') #刪除指定的key # # r.flushdb() #清除當(dāng)前數(shù)據(jù)庫(kù)里面所有的key # # r.flushall() #清除所有數(shù)據(jù)庫(kù)里面的所有key # print(r.keys())#獲取到當(dāng)前數(shù)據(jù)庫(kù)里面有哪些key # print(result)# print(result.decode()) #decode是把bytes類型變成字符串# 寫一個(gè)不存在的key,會(huì)怎樣# hash類型# print(r.hget('szz_stu','dsk'))print(r.hset('szz_stu', 'gxn', 'sdfsdfsfsf')) # r.hdel('szz_stu','gxn') r.hmset('szz_stu', {"ldd": 'dsk', 'cwl': 'brf'}) # 批量往hash類型里面set數(shù)據(jù)# r.hset('szz_stu','gxn','{"money":11111,"session_id":"xxxxxxx"}') print(r.hgetall('szz_stu')) print(r.type('szz_stu'))# 把a(bǔ)的數(shù)據(jù),全部遷移到b上面# 1、連上aredis和bredis # 2、從aredis里面獲取到所有的key [ ] # 3、判斷key的類型,如果是string類型,用get獲取數(shù)據(jù),set到新的bredis里面# 遷移redis host = '127.0.0.1' passwd = 'xxx'r = redis.Redis(host=host, password=passwd, db=15, decode_responses=True) # 0-15 r2 = redis.Redis(host=host, password=passwd, db=15, decode_responses=True, port=6378) # 0-15 for k in r.keys():if r.type(k) == 'string':value = r.get(k)r2.set(k, value)elif r.type(k) == 'hash':value = r.hgetall(k) # 首先獲取到hashkey里面的所有數(shù)據(jù)r2.hmset(k, value) # 然后把所有的數(shù)據(jù)set進(jìn)去 # 管道# p = r.pipeline() #新建了一個(gè)管道,操作比較多的時(shí)候用管道 # p.set('abc','aa') # p.get('xx') # p.hget('xxx') # p.execute() #執(zhí)行

?

nnlog寫日志模塊

import nnloglog = nnlog.Logger('test.log', level='error', backCount=5, when='S') # D H M S log.debug('返回結(jié)果...') # 一些調(diào)試信息,看變量值這些 log.info('info...') # 一些提示信息 log.warning('waring') # 出警告了 log.error('error...') # 出錯(cuò)的時(shí)候打印的# log.surprise()

?

request模塊調(diào)用接口,可以實(shí)現(xiàn)get、post、下載等

import requests# url = 'http://api.nnzhp.cn/api/user/stu_info' # d = {'stu_name':'礦泉水2'} # # result = requests.get(url, d) # print(result.json()) # 結(jié)果轉(zhuǎn)成字典 # print(result.text) # 結(jié)果轉(zhuǎn)成字符串方便寫入文件# url = 'http://api.nnzhp.cn/api/user/login' # data = {'username':'niuhanyang', 'passwd':'aA123456'} # req = requests.post(url, data) # print(req.json()) url = 'http://api.nnzhp.cn/api/user/gold_add' data = {'stu_id': 2, 'gold': 1111} # cookie = {'niuhanyang':'b500d8a2f545102c8afa85135224149c'} cookie2 = {'cookie': 'niuhanyang=b500d8a2f545102c8afa85135224149c'} # 這種方式抓包到數(shù)據(jù)可以直接粘貼,不用轉(zhuǎn)k-v r = requests.post(url, data, headers=cookie2) print(r.text)#入?yún)⑹莏son的 # data = { # "name": "礦泉水33333", # "grade": "雙子座", # "phone": "12123624321", # "sex": "未知", # "addr": "天通苑", # "age": 38 # } # # url = 'http://api.nnzhp.cn/api/user/add_stu' # req = requests.post(url,json=data) # print(req.text)# url='http://api.nnzhp.cn/api/file/file_upload' # data = {'file':open('上周作業(yè).py','rb')} # req = requests.post(url,files=data) # print(req.text)# url = 'http://aliuwmp3.changba.com/userdata/userwork/12107482.mp3' url='https://aliimg.changba.com/cache/photo/18189396_640_640.jpg' req = requests.get(url) with open('aqmm.jpg','wb') as fw:fw.write(req.content)

?

模塊
1、一個(gè)python文件就是一個(gè)模塊。
2、
1、自己寫的
2、標(biāo)準(zhǔn)模塊,os time random hashlib
3、第三方模塊 pymysql xlwt

1、import模塊的實(shí)質(zhì)就是把這個(gè)python文件執(zhí)行了一遍(調(diào)試模塊代碼時(shí),寫在 if __name__ == '__main__': 下面的調(diào)試執(zhí)行代碼,在import的時(shí)候不會(huì)被執(zhí)行) 2、查找模塊的順序
1、導(dǎo)入模塊的時(shí)候首先從當(dāng)前目錄下找
2、如果當(dāng)前目錄下沒有,就是去python的環(huán)境變量里面找


Mac OX 設(shè)置pip國(guó)內(nèi)鏡像,下載速度超快 $ vim ~/.pip/pip.conf[global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/fatenet/p/10879092.html

總結(jié)

以上是生活随笔為你收集整理的测试自动化学习7的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。