python的多线程
摘要:实现代码如下: #多线程 import threading import time class test: def test1(self,a): for i in range(3): print(a) time.sleep(2) def test2(self,b): for i in range(5
阅读全文
posted @
2020-01-11 21:10
badbadboy
阅读(155)
推荐(0)
python的多进程
摘要:实现代码如下: #多进程 import time import multiprocessing class test: def test1(self,a): for i in range(3): print(a) time.sleep(1) def test2(self,b): for i in r
阅读全文
posted @
2020-01-11 20:14
badbadboy
阅读(186)
推荐(0)
python实现读写txt文件
摘要:一、读写模式: w:向文件中写入内容,w会清空原来文本内容 a:向文件中追加内容 r:从文件中读取内容 wb:以二进制形式写入内容。 rb:以二进制形式读文件内容 ab:以二进制形式追加内容 a+、r+、w+:混合形式,即可读可写 二、读 1. 方法一: f = open(文件路径,读模式) #将文
阅读全文
posted @
2020-01-11 19:22
badbadboy
阅读(712)
推荐(0)
python的封包和解包
摘要:#封包 def as1(*a): print(a) as1(1,2,3) #解包 def as2(a): print(*a) as2([1,2,3])
阅读全文
posted @
2020-01-11 19:13
badbadboy
阅读(522)
推荐(0)
python的time库常用的函数介绍
摘要:#time库 import time #线程推迟时间 time.sleep(3) #时间戳 print(time.time()) #返回日期、时间、星期 print(time.strftime('%Y/%m/%d %H:%M:%S %A')) #返回时间信息元祖 print(time.localti
阅读全文
posted @
2020-01-11 19:05
badbadboy
阅读(563)
推荐(0)
python的参数传递方式
摘要:#参数传递方式 a=1 b=22 #第一种 print(f'{a}hello{b}') #第二种 #整数:%d 小数:%f 字符串:%s print('%dhello%d'%(a,b))
阅读全文
posted @
2020-01-09 19:22
badbadboy
阅读(178)
推荐(0)
python的数据类型
摘要:1. 数字 #整型 print(int(3.41)) #浮点型 print(float(3)) #复数 print(complex(2,3)) #四舍五入为整数 print(round(3.45)) 2. 字符串 #字符串str a=' asaDf ' #转为字符串 b=12345 print(st
阅读全文
posted @
2020-01-09 19:20
badbadboy
阅读(217)
推荐(0)
正则表达式
摘要:推荐:https://any86.github.io/any-rule/ 一、基本语法 1、[] [abc] 查找方括号之间的任何字符 [^abc] 查找任何不在方括号之间的字符 [0-9] 查找任何从0-9的数字 [A-z] 查找任何从大写A到小写z的字符 2、元字符 . 查找单个字符,除换行符
阅读全文
posted @
2020-01-09 13:07
badbadboy
阅读(172)
推荐(0)
python实现操作mysql数据库
摘要:实现代码如下: #mysql数据库的查询等 import pymysql from xctest_tools.get_ReadTxt import * class mysql: def __init__(self): # 读取配置文件进行连接 self.db=ReadTxt().read_txt("
阅读全文
posted @
2019-11-28 20:37
badbadboy
阅读(244)
推荐(0)
python实现读取并处理excel单元格中的数据
摘要:实现代码如下: # 将数据单元格(格式为:参数名=值)里的数据以键值对的形式放入字典中,返回该字典 class get_string: def cut_string(self,string): # 将字符串以\n(换行符)分割 li_1 = string.split('\n') di = {} tr
阅读全文
posted @
2019-11-28 20:09
badbadboy
阅读(3994)
推荐(0)
python实现读取配置文件
摘要:实现代码如下: # 读取配置文件,取其值组成列表class ReadTxt: def read_txt(self,path): li_info = [] with open(path) as f: li = f.readlines() for i in li: a = i.split("=")[1]
阅读全文
posted @
2019-11-28 19:48
badbadboy
阅读(273)
推荐(0)
python实现读取excel
摘要:实现代码如下: #读取excel,将每行数据放入一个列表,将所有列表放入一个列表形成二维列表,返回该二维列表 import xlrd class ReadExcel: def read_excel(self,path): book = xlrd.open_workbook(path) sheet =
阅读全文
posted @
2019-11-28 19:42
badbadboy
阅读(196)
推荐(0)
python实现获取文件夹中的最新文件
摘要:实现代码如下: #查找某目录中的最新文件import osclass FindNewFile: def find_NewFile(self,path): #获取文件夹中的所有文件 lists = os.listdir(path) #对获取的文件根据修改时间进行排序 lists.sort(key=la
阅读全文
posted @
2019-11-27 16:43
badbadboy
阅读(3176)
推荐(0)
python实现获取文件的绝对路径
摘要:实现代码如下: #获取文件的绝对路径import osclass GetPath: def get_path(self,path): r=os.path.abspath(path) return rif __name__ == '__main__': a=GetPath().get_path('./
阅读全文
posted @
2019-11-26 20:59
badbadboy
阅读(7938)
推荐(0)
python实现压缩文件成zip格式
摘要:实现代码如下: #压缩文件 import time,zipfile class zip: def get_zip(self,files,zip_name): zp=zipfile.ZipFile(zip_name,'w', zipfile.ZIP_DEFLATED) for file in file
阅读全文
posted @
2019-11-26 20:56
badbadboy
阅读(11101)
推荐(1)
python实现自动发送邮件
摘要:Python发送邮件成功的前提,应是先开启授权码。目前使用广泛的邮箱有:163邮箱、qq邮箱等。 163邮箱开启授权码的方法如下图: qq邮箱开启授权码的方法如下图: 接下来代码的实现: import smtplib from email.mime.text import MIMEText from
阅读全文
posted @
2019-11-26 19:28
badbadboy
阅读(923)
推荐(0)