python测试开发自学每周一练
Table of Contents
python每周一练
每周五发布python需求,所有需求都来自实际企业。下周五发布参考答案。
-
技术支持 (可以加钉钉pythontesting邀请加入) qq群:144081101 591302926 567351477
-
道家技术-手相手诊看相中医等钉钉群21734177 qq群:391441566 184175668 338228106 看手相、面相、舌相、抽签、体质识别。服务费50元每人次起。请联系钉钉或者微信pythontesting
接口自动化性能测试数据分析人工智能从业专家一对一线上培训大纲
2018-06-06 json格式转换
现有 人脸标注的海量数据,部分参见:data
要求输出: 1,files.txt
image_1515229323784.ir image_1515235832391.ir image_1515208991161.ir image_1515207265358.ir image_1521802748625.ir image_1515387191011.ir ... |
2, 坐标信息 poses.txt 文件名、left, top, right, buttom,width,height
image_1515229323784.ir,4,227,234,497,230,270 image_1515235832391.ir,154,89,302,240,148,151 image_1515208991161.ir,76,369,309,576,233,207 image_1515207265358.ir,44,261,340,546,296,285 ... |
3,比对文件:
首先:# 后面的为序列号,从1开始递增 3 640 480 1及后面3行暂时视为固定。后面一行1 后面为4个坐标left, top, right, buttom。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # 1 image_1515229323784.ir 3 640 480 1 0 1 1 4 227 234 497 # 2 image_1515235832391.ir 3 640 480 1 0 1 1 154 89 302 240 # 3 ... |
2018-06-01 正则表达式及拼音排序
有某群的某段聊天记录
现在要求输出排序的qq名,结果类似如下:
[..., '本草隐士', 'jerryyu', '可怜的樱桃树', '叻风云', '欧阳-深圳白芒', ...] |
需求来源:有个想批量邀请某些qq群的活跃用户到自己的群。又不想铺天盖地去看聊天记录。
参考资料:python文本处理库
参考代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #!/usr/bin/python3 # -*- coding: utf-8 -*- # Author: xurongzhong@126.com wechat:pythontesting qq:37391319 # 技术支持 (可以加钉钉pythontesting邀请加入) # qq群:144081101 591302926 567351477 # CreateDate: 2018-6-1 import re from pypinyin import lazy_pinyin name = r'test.txt' text = open(name,encoding='utf-8').read() #print(text) results = re.findall(r'(:\d+)\s(.*?)\(\d+', text) names = set() for item in results: names.add(item[1]) keys = list(names) keys = sorted(keys) def compare(char): try: result = lazy_pinyin(char)[0][0] except Exception as e: result = char return result keys.sort(key=compare) print(keys) |
执行示例:
1,把qq群的聊天记录导出为txt格式,重命名为test.txt
2, 执行:
$ python3 qq.py ['Sally', '^^O^^', 'aa催乳师', 'bling', '本草隐士', '纯中药治疗阳痿早泄', '长夜无荒', '东方~慈航', '干金草', '广东-曾超庆', '红梅* 渝', 'jerryyu', '可怜的樱桃树', '叻风云', '欧阳-深圳白芒', '勝昔堂~元亨', '蜀中~眉豆。', '陕西渭南逸清阁*无为', '吴宁……任', '系统消息', '于立伟', '倚窗望岳', '烟霞霭霭', '燕子', '张强', '滋味', '✾买个罐头 吃西餐', '【大侠】好好', '【大侠】面向大海~纯中药治烫伤', '【宗师】吴宁……任', '【宗师】红梅* 渝', '【少侠】焚琴煮鹤', '【少侠】笨笨', '【掌门】溆浦☞山野人家'] |
2018-05-25 旋转图片
把/home/andrew/code/tmp_photos2的jpg图片旋转270度,放在/home/andrew/code/tmp_photos3
参考资料:python图像处理库
要求实现的命令行界面如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | $ python3 rotate.py -h usage: rotate.py [-h] [-t TYPE] [-a ANGLE] [--version] src dst 功能:旋转图片 示例: $ python3 rotate.py /home/andrew/code/tmp_photos2 /home/andrew/code/tmp_photos3 -a 270 把/home/andrew/code/tmp_photos2的jpg图片旋转270度,放在/home/andrew/code/tmp_photos3 positional arguments: src 源目录 dst 目的目录 optional arguments: -h, --help show this help message and exit -t TYPE 文件扩展名, 默认为jpg -a ANGLE 旋转角度,默认为90度,方向都为逆时针。 --version show program's version number and exit |
旋转前:

旋转后

需求来源: 用户拍的图片人脸未必是头在上,下巴在下面,但是人脸识别的时扶正的识别效果比较好,为此...
参考代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import glob import os import argparse from PIL import Image import photos import data_common description = ''' 功能:旋转图片 示例: $ python3 rotate.py /home/andrew/code/tmp_photos2 /home/andrew/code/tmp_photos3 -a 270 ''' parser = argparse.ArgumentParser(description=description, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('src', action="store", help=u'源目录') parser.add_argument('dst', action="store", help=u'目的目录') parser.add_argument('-t', action="store", dest="type", default="jpg", help=u'文件扩展名, 默认为jpg') parser.add_argument('-a', action="store", dest="angle", default=90, type=int, help=u'旋转角度,默认为90度,方向都为逆时针。') parser.add_argument('--version', action='version', version='%(prog)s 1.0 Rongzhong xu 2018 04 26') options = parser.parse_args() data_common.check_directory(options.dst) files = data_common.find_files_by_type(options.src, filetype=options.type) photos.rotate(files, options.dst, options.angle) |