![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
冲田小姐姐吃糖
短腿猫天下第一可爱
展开
-
Pyqt5重置主窗口中的所有组件(重新初始化)
因为项目需要做一个填写信息的软件,应用场景是填写完一个人的信息点击完成,再填写下一个人的,这样的话就需要将组件中填写的值清空或者还原到初始化状态,经过一下午的研究发现可以这样做class mWindow(QMainWindow, Ui_MainWindow): def __init__(self): super(mWindow, self).__init__() self.setFixedSize(1705, 929) self.setupU原创 2021-01-30 13:26:45 · 5950 阅读 · 9 评论 -
Pyqt5重启QMainWindow(主窗口)
参考官方文档:https://wiki.qt.io其核心思想就是只要满足我规定的错误代码,就不停的循环创建新窗口。def restart(): EXIT_CODE_REBOOT = -11231351 qDebug("Performing application reboot...") qApp.exit(EXIT_CODE_REBOOT)if __name__ == '__main__': while True: try:原创 2021-01-30 13:20:38 · 2310 阅读 · 0 评论 -
实现pyqt5中listwidget右键菜单添加、删除、修改功能
代码如下:class mWindow(QMainWindow, Ui_MainWindow): def __init__(self): super(mWindow, self).__init__() self.setFixedSize(1125, 832) self.setupUi(self) self.setWindowTitle(self.label.text()) self.listWidget.conte原创 2021-01-05 14:23:05 · 2672 阅读 · 1 评论 -
pymssql (1366, “Incorrect string value: ‘\\xF0\\x9F\\x92\\x8E W...‘ for column ‘AppName‘ at row 1)
在处理emoji时,报错1366,原因是编码造成的在mysql8里,字符集默认就是 utf8mb4,已支持emojipython3默认就是utf8原因就出在两个字符集上,utf8mb4是utf8的超集,mb4是most bytes 4的意思,专门用来兼容四字节的unicode处理emoji时需要字符集支持unicode,utf8mb4是没问题的,但是utf8不行只需要将python连接mysql的默认格式由utf8改为utf8mb4即mysql_pool = Pool(maxAct原创 2020-12-29 16:35:41 · 677 阅读 · 0 评论 -
yowsup的一些使用说明
安装python版本和库:- python>=2.7,<=3.7- consonance==0.1.3-1- python-axolotl==0.2.2- protobuf>=3.6.0- pyopenssl==19.0.0- pysocks==1.7.1-six==1.10- yowsup==3.2.31 注册请求注册码yowsup-cli registration –requestcode sms –phone 86xxx######## –cc .原创 2020-09-29 15:59:16 · 3208 阅读 · 1 评论 -
python线程池 ThreadPoolExecutor 的用法及实战
✨ 前言从Python3.2开始,标准库为我们提供了 concurrent.futures 模块,它提供了 ThreadPoolExecutor (线程池)和ProcessPoolExecutor (进程池)两个类。相比 threading 等模块,该模块通过 submit 返回的是一个 future 对象,它是一个未来可期的对象,通过它可以获悉线程的状态主线程(或进程)中可以获取某一个线程(进程)执行的状态或者某一个任务执行的状态及返回值:主线程可以获取某一个线程(或者任务的)的状态,以及返回转载 2020-11-25 17:54:29 · 2981 阅读 · 0 评论 -
python SQLite3 连接池
SQLite3 特点简洁 api 很简洁,使用方便易上手 轻便 零配置,无需安装配置管理 可嵌入 C语言编写,精致小巧吗,易于嵌入到其他设备 无网络 在一些终端使用,很合适 快速的 除了在高并发的写的性能上可能低于mysql postgresql外,其他的都不慢SQLite3 连接池# -*- coding: utf-8 -*-import timefrom Queue import Queueclass PoolException(Exception): pass转载 2020-11-16 10:58:05 · 1708 阅读 · 0 评论 -
python导出项目依赖包与导入项目依赖包
使用平时导出依赖一般都是pip freeze >requirements.txt这种方式导出的是当前python环境中所有的包,有些库不是必需的也跟着导出来,安装的时候也过于麻烦。这种时候就要使用pipreqs,它只会导出当前项目运行所依赖的包。下载命令:pip install pipreqs使用命令如下,进入项目的根目录后输入如下命令pipreqs ./然后会在当前目录下生成requirements.txt文件问题如果生成文件...原创 2020-11-13 15:21:09 · 1603 阅读 · 0 评论 -
Pyqt5-designer使用
将ui文件转为py文件pyuic5 -o {name}.py {name}.ui原创 2020-11-12 10:30:04 · 95 阅读 · 0 评论 -
解决error: command ‘x86_64-linux-gnu-gcc‘ failed with exit status 1
查看自己python的版本,然后下载自己版本Python的devel,比如python3.7.7就是sudo apt-get install python3.7-dev安装依赖库sudo apt-get install build-essential python3-dev libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev zlib1g-dev...原创 2020-11-11 14:54:04 · 9542 阅读 · 0 评论 -
windows用xrdp方式远程桌面连接ubuntu
windows系统:win10ubuntu系统:18.04.5原创 2020-11-11 13:17:42 · 1865 阅读 · 0 评论 -
ubuntu安装python3.7.7
Ubuntu自带了Python2.7和Python3.5,但是我现在想用Python3.7.7一、下载在官网下载tgz文件,https://www.python.org/downloads/release/python-377/二、安装python3.7补充知识: 源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install)。 configure是一个可执行脚本,它有很多选项,使用命令./configure --help输出...原创 2020-11-11 13:12:44 · 605 阅读 · 0 评论 -
tkinter拖拽读取文件
首先要下载windnd库pip install windndimport tkinter as tkimport windndfrom tkinter.messagebox import showinfodef dragged_files(files): msg = '\n'.join((item.decode('gbk') for item in files)) showinfo("拖拽文件路径",msg)if __name__ == '__main__':原创 2020-11-05 17:13:26 · 4824 阅读 · 10 评论 -
multiprocessing,多进程的应用
multiprocessing多进程+定时器def func(i): time.sleep(4) print(i)def test(): print("T1")def MyTimer(): print("定时任务已启动") scheduler = BlockingScheduler() scheduler.add_job(test,'interval', days=1) scheduler.start()if __name__ ==原创 2020-10-30 13:03:58 · 249 阅读 · 0 评论 -
atexit—退出处理器
将此函数作为装饰器不管程序在哪里崩溃,都会执行注册过的函数(ide关闭的不算)import atexitimport time@atexit.registerdef e(): print('end')if __name__ == '__main__': print("start") time.sleep(10)文档:atexit — 退出处理器...原创 2020-10-30 12:57:40 · 162 阅读 · 0 评论 -
对中文字符的判断
中文字符的编码范围\u4e00 - \u9fff判断是否为纯中文def is_CN(str): for i in str: if u'\u4e00' <= i <= u'\u9fff': return True return False判断是否为纯英文import stringdef is_En(str): for i in str: if i not in string.ascii原创 2020-10-26 16:10:45 · 1075 阅读 · 0 评论 -
Python操作Mysql之连接池的用法
最近需要做一个频繁操作数据库的应用,如果频繁的建立、关闭连接则会浪费很大部分资源,于是在网上搜索连接池的用法,如下:首先Python3中操作数据库需要用到的库为pymysql,下载命令pip installpymysql简单的mysql操作import pymysqlif __name__== "__main__": db = pymysql.connect(host="数据库地址", user="testuser", password="test123",databa.原创 2020-10-23 17:33:01 · 2607 阅读 · 0 评论 -
Python 线程池ThreadPoolExecutor初识
线程池的使用线程池的基类是 concurrent.futures 模块中的 Executor,Executor 提供了两个子类,即 ThreadPoolExecutor 和 ProcessPoolExecutor,其中 ThreadPoolExecutor 用于创建线程池,而 ProcessPoolExecutor 用于创建进程池。如果使用线程池/进程池来管理并发编程,那么只要将相应的 task 函数提交给线程池/进程池,剩下的事情就由线程池/进程池来搞定。Exectuor 提供了如下常用方法:转载 2020-10-22 21:13:14 · 704 阅读 · 0 评论 -
scheduler定时任务的基础使用
创建一个定时任务class MyTimer(threading.Thread): # 我的定时任务 def __init__(self): threading.Thread.__init__(self) def run(self): print("定时任务已启动") scheduler = BlockingScheduler() scheduler.add_job(A,'interval', days=1) ...原创 2020-10-16 11:26:57 · 15553 阅读 · 1 评论 -
subprocess获取命令行输出结果并且设置超时
使用communicate方法process = subprocess.Popen(cmd,stdin=subprocess.PIPE, stdout=subprocess.PIPE)output, unused_err = process.communicate(timeout=30)output = output.decode("utf-8")print(output)原创 2020-10-13 19:04:25 · 3031 阅读 · 1 评论 -
删除文件夹及文件夹里的文件
思路就是先删除里面的文件,再删除文件夹,如果不直接删除文件夹会报错def remove_dir(file): for root, dirs, files in os.walk(file, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root原创 2020-10-10 18:43:03 · 295 阅读 · 0 评论 -
定时结束线程
参考的文章:https://www.oschina.net/question/172446_2159505先简单粗暴的解决,以后再优化(暂时不考虑强制停止线程的安全性等问题)thread_dict = {}def check_ThreadDict(): for tid,starttime in thread_dict.items(): if time.time() - starttime >=60: #大于一分钟的就kill stop_th原创 2020-10-10 11:32:37 · 434 阅读 · 1 评论