![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python3基础
放开那只大熊猫
热爱学习,热爱测试(づ ●─● )づ
展开
-
Python+flask基础应用
#!/usr/bin/env python3# coding: utf-8from flask import Flask, request, make_responseimport jsonapp = Flask(__name__)# 只接受get方法访问@app.route("/getTest", methods=["GET"])def get_test(): # 获取URL?后面所有的参数和值 args = request.args name = args.原创 2021-09-23 17:55:11 · 210 阅读 · 0 评论 -
python3:批量创建MySQL数据表
#!/usr/bin/env python3# coding: utf-8# author: hyhimport pymysqlclass CreateTable: def __init__(self, tab_num, host, port, user, passwd, db): self.tab_num = tab_num self.host = host self.port = port self.user = u.原创 2020-09-16 23:06:57 · 1113 阅读 · 0 评论 -
python:logging模块封装(二)
#!/usr/bin/env python3# coding: utf-8# author: hyhimport loggingimport osimport timefrom logging import handlersclass GetLogger: """单例模式""" __instance = None def __new__(cls, *args, **kwargs): if not cls.__instance: .原创 2020-08-05 22:23:42 · 321 阅读 · 0 评论 -
python3:图形验证码识别
参考文章:https://www.py.cn/jishu/jichu/12576.htmlhttps://github.com/simonflueckiger/tesserocr-windows_build/releases原创 2020-04-28 19:54:44 · 422 阅读 · 0 评论 -
python3:excel操作之读取数据并返回字典 + 写入数据
excel写入数据,使用openpyxl库class WriteExcel: def __init__(self,path): self.path = path def write_excel(self, sheet_name, content): """ 在excel指定sheet中的写入指定内容,以追加方式 ...原创 2020-04-27 17:07:41 · 2934 阅读 · 0 评论 -
Python js/jQuery用法
jQuery基础:https://www.runoob.com/jquery/jquery-ref-selectors.htmlselenium 执行jQuery/js语法driver.execute_script(jQuery/js)https://www.cnblogs.com/zhongyehai/p/9576327.htm原创 2020-04-09 17:20:38 · 356 阅读 · 0 评论 -
Python3:查询MYSQL并以字典接收
cursor这里有个属性:description。获取的是数据库每个栏位(字段,列)情况:(('id', 3, None, 11, 11, 0, False), ('type', 253, None, 5, 5, 0, False)result_dict = dict(zip([col[0] for col in cursor.description],[col for col in c...原创 2020-03-19 11:02:00 · 456 阅读 · 0 评论 -
python:实现日期加减操作
pip install python-dateutilimport datetimefrom dateutil.relativedelta import relativedeltasdate = datetime.datetime.strptime('2019.01.05','%Y.%m.%d')edate = sdate + relativedelta(months=1)pr...原创 2020-03-31 10:23:46 · 974 阅读 · 0 评论 -
python3+selenium:截图并保存到指定文件夹
一、截图方法1.get_screenshot_as_file(self, filename)--这个方法是获取当前window的截图,出现IOError时候返回False,截图成功返回True。filename参数是保存文件的路径。driver.get_screenshot_as_file('/Screenshots/foo.png')2.get_screenshot_as...原创 2020-01-12 17:33:00 · 5013 阅读 · 2 评论 -
python3:日志模块封装
#!/usr/bin/env python# coding: utf-8import loggingimport timeimport osdef get_log(log_model_name, style='console'): """ :param log_model_name: 要打印日志的模块名 :param style: 日志打印方式,conso...原创 2020-01-12 16:04:51 · 1118 阅读 · 0 评论 -
python+selenium:数据参数化(从文件读取数据)
#!/usr/bin/env python# -*- coding=utf-8 -*-# coding: utf-8from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom common.read_txt import read_txt# from co...原创 2020-01-12 10:59:02 · 1425 阅读 · 0 评论 -
python3:从excel中读取数据,并以字典组成的列表返回
#!/usr/bin/env python# coding: utf-8import xlrddef read_xlsx(path, sheet): # book = xlrd.open_workbook(path) # 打开excel表 with xlrd.open_workbook(path, 'rb') as book: table =...原创 2020-01-12 10:45:48 · 1866 阅读 · 0 评论 -
Python3:pymysql模块详解
https://www.jb51.net/article/167429.htm原创 2020-01-09 22:24:59 · 281 阅读 · 0 评论 -
Python3:遍历文件夹中文件并修改后缀名
公司对安全要求很高,不允许邮件发送代码后缀文件,但是需要用到一些python库,而PC又无法访问外网,不能先把python库文件转换为“.txt”格式的发送了,才有了下面的轮子:#!/usr/bin/env python# -*- coding=utf-8 -*-# coding: utf-8import osimport shutildef show_files(path...原创 2020-01-09 20:57:21 · 1259 阅读 · 0 评论 -
Python:函数加括号与否的区别
def a(x): def b(y): print('执行b函数') return x+y print('执行a函数') return bprint(a(2)(3)) # 执行了b函数print(a(7)) # 没执行b函数a-->函数a的内存地址a(x) -->调用a方法,返回b函数对象相当于--&g...原创 2019-06-07 18:36:12 · 128 阅读 · 0 评论 -
python基础之yield
yield的作用就是把一个函数变成一个generator,带有yield的函数不再是一个普通函数,Python解释器会将其视为一个generatoryield的功能:1.与return类似,都可以返回值,但不一样的地方在于yield返回多次值,而return只能返回一次值;迭代一次遇到yield时就返回yield后面的值。重点是:下一次迭代时,从上一次迭代遇到的yield后面的代码开始执行...原创 2018-12-21 22:44:31 · 127 阅读 · 0 评论 -
python基础:内置函数
常见内置函数:help()dir()vars()type()import tempimport tempreload(temp)id([12])#is------------------cmp(2,3)cmp(2,2)cmp(2,1)cmp(10,1)abs()bool()divmod():分页时用到max()min()...原创 2018-12-22 20:32:03 · 95 阅读 · 0 评论 -
python3基础:random
random.random():生成0~1之间的随机数random.randint():生成闭区间内随机整数random.randrange():生成开区间内的随机数#!/usr/bin/env python# coding=utf-8# 随机生成一个大写或小写字母或数字的6位验证码import random# 定义一个列表接收字符串code = []for i i...原创 2018-12-22 22:35:05 · 609 阅读 · 0 评论 -
python3基础:MD5加密详解
#!/usr/bin/env python# coding=utf-8import hashlib# 创建加密对象m = hashlib.md5()# 更新加密对象m.update('admin'.encode('utf-8'))# 以16进制的形式返回m.hexdigest()print(m)注意:若写成m.update('admin'),则会报错“Unicode-o...原创 2018-12-22 23:25:24 · 512 阅读 · 0 评论 -
python3基础:re模块
compile:返回一个对象 match('正则表达式', '匹配目标'): 从开头开始匹配,若匹配成功则返回一个匹配结果对象,可以使用group方法获取对象中的值(只查找一个匹配结果);若开始没匹配到则直接返回一个None search('正则表达式', '匹配目标'): 从整个字符串中一直匹配直到匹配成功为止,若匹配成功则返回一个匹配结果对象 ,可以使用group方法获取对象中...原创 2018-12-23 17:20:53 · 270 阅读 · 0 评论 -
python3基础:装饰器
装饰器本身是一个函数,使用“@”与被装饰函数连接;程序运行装饰器函数时,会先对装饰器函数从上到下解释并存到内存#!/usr/bin/env python# coding=utf-8def outer(fun): def wrapper(args0): print('Check') # 使用result变量接收原函数的返回值,并返回 ...原创 2018-12-23 18:47:38 · 111 阅读 · 0 评论 -
python3基础:常见的数据格式处理方法
1、strip():用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列;返回新字符串语法:str.strip([chars]); 2、split():通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则分隔 num+1 个子字符串;返回字符串列表语法:str.split(str="", num=string.count(str)) ...原创 2018-12-24 22:22:57 · 190 阅读 · 0 评论 -
python3基础:列表解析
列表解析是Python迭代机制的一种应用,常用于实现创建新的列表。 列表解析式简化了代码,使代码的可读性增强;编译器在内部作了优化,不会因为简写而影响效率,反而提高了效率基本语法:[expression for iter_val in iterable]练习题:生成一个列表,元素是1-9,返回这个列表元素自增1后平方的列表 [(i+1)**2 for i in range(10)]...原创 2018-12-24 22:46:26 · 1146 阅读 · 0 评论 -
python3练习4:从txt或csv文件中读取数据并以字典存储返回
1、读取txt文件并返回字典文件内容如下:代码如下:#!/usr/bin/env python# coding=utf-8import codecsdef read_txt(path): txt_dict = {} with codecs.open(path, 'r', 'utf-8') as config: for line in c...原创 2018-12-24 22:47:54 · 11479 阅读 · 1 评论 -
python3+selenium多线程
· 创建线程函数· 创建要传入的args参数· for循环创建线程 from time import sleep, ctimeimport threading# 创建超级播放器def super_player(file_, loop): for i in range(2): print('start playing: %s !%s' % (file_...原创 2019-02-21 14:31:09 · 4705 阅读 · 2 评论 -
Python常见错误
1、UnboundLocalError: local variable 'xxx' referenced before assignment参考链接:http://blog.csdn.net/onlyanyz/article/details/45009697https://www.cnblogs.com/fendou-999/p/3822028.html2、IndentationE...原创 2019-05-02 18:09:45 · 11301 阅读 · 0 评论 -
python面向对象(一)
面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可能不同。仍以Student类为例,在Python中,定义类是通过class关键字:class Student(object): passclass后面紧接着是类名,即Stude...原创 2019-05-02 20:46:59 · 95 阅读 · 0 评论 -
python3基础:json模块详解
json模块详解:https://www.cnblogs.com/tjuyuan/p/6795860.html原创 2019-05-13 21:17:08 · 162 阅读 · 0 评论 -
python如何查询模块的文件位置
>>> import requests>>> print(requests.__file__)C:\Python\Python36\lib\site-packages\requests\__init__.py>>>原创 2019-05-06 21:32:03 · 5702 阅读 · 0 评论 -
python3基础:异常处理及python常见异常类型总结
1、try...except...#!/usr/bin/env python# coding=utf-8import codecsdef get_webinfo(path): web_info = {} with codecs.open(path, 'r', 'utf-8') as config: for line in config.readlin...原创 2018-12-26 22:31:19 · 1130 阅读 · 0 评论