随笔分类 - Python
Python
摘要:主窗口main.py from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, QMetaObject, QObject, QPoint, QRect, QSize, QTime, QUrl, Qt) from
阅读全文
摘要:实现功能 在MainWindow点击按钮“Open New Window”打开SubWindow 在SubWindow 点击按钮“Close the Window” 关闭 SubWindow 有QtDesigner设计两个窗口,转化为main_ui.py、sub_ui.py main_ui.py f
阅读全文
摘要:import sys from PySide6 import QtCore,QtWidgets from PySide6.QtWidgets import * from menu_ui import Ui_MainWindow //导入ui class menu(QMainWindow): def
阅读全文
摘要:1.动态加载 import sys from PySide6 import QtCore,QtWidgets from PySide6.QtWidgets import * from PySide6.QtUiTools import QUiLoader class readfile(QWidget)
阅读全文
摘要:通过QtDesigner将ui文件转存为py文件 不继承Ui_Form import sys from PySide6 import QtCore,QtWidgets from PySide6.QtWidgets import * from ui_test import Ui_Form class
阅读全文
摘要:Simple example import time import concurrent.futures start = time.perf_counter() def do_something(seconds): print(f'sleeping {seconds} second(s)...')
阅读全文
摘要:Simple example import time import multiprocessing start = time.perf_counter() def do_something(): print('sleeping 1 second...') time.sleep(1) print('D
阅读全文
摘要:Simple Example 1 import time import threading start = time.perf_counter() def do_something(): print('sleeping 1 second...') time.sleep(1) print('Done
阅读全文
摘要:ModbusTCP数据帧 ModbusTCP的数据帧可分为两部分:MBAP+PDU。 报文头MBAP MBAP为报文头,长度为7字节 | 事务处理标识 | 协议标识 | 长度 | 单元标识符 | | | | | | | 2字节 | 2字节 | 2字节 | 1字节 | | 内容 | 解释 | | |
阅读全文
摘要:面对网络协议,在组包拆包时,python提供了struct模块,可以在python值和C语言的结构体之间相互转换。 格式字符串 格式字符串的第一个字符可用于指示打包数据的字节顺序,大小和对齐方式: | 字符 | 字节顺序 | 大小 | 对齐方式 | | | | | | | @ | 按原字节 | 按原
阅读全文
摘要:我现在用的是Debian11,按照网上搜到的方法在Crontab里定时执行python脚本,可是没有反应 网上的方法大多是: */1 * * * * python 文件路径+文件名 或者是 */1 * * * * /usr/bin/python 文件路径+文件名 尝试以后,都不能用。 发现只有在当前
阅读全文
摘要:1 import usb.core 2 3 dev = usb.core.find(idVendor=0x17ef,idProduct = 0x600e) 4 ep = dev[0].interfaces()[0].endpoints()[0] 5 6 7 i = dev[0].interfaces
阅读全文
摘要:df.to_sql参数介绍: name:SQL表的名称。 con:sqlalchemy.engine.Engine或sqlite3.Connection 使用SQLAlchemy可以使用该库支持的任何数据库。为sqlite3.Connection对象提供了旧版支持。 if_exists:{'fail
阅读全文
摘要:1 一行 For 循环 #For循环在一行mylist = [200, 300, 400, 500] #正常方式 result = [] for x in mylist: if x > 250: result.append(x) print(result) # [300, 400, 500] #一行
阅读全文
摘要:pandas.DataFrame 进行新增列操作的五种方法:insert、reindex、loc、obj[‘col’]、concat。 data: a b c 0 1 2 3 1 4 5 6 2 7 8 9 一、insert 方法 使用 pandas 的 insert 方法,第一个参数指定插入列的位
阅读全文
摘要:1.双y轴绘制 关键函数:twinx() # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from matplotlib import rc rc('mathtext', default='regu
阅读全文
摘要:####UI文件 # -*- coding: utf-8 -*- from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, QMetaObject, QObject, QPoint, QRect, QSize,
阅读全文
摘要:import matplotlib.pyplot as plt from scipy.optimize import curve_fit import numpy as np def func(x, a, b, c): # 拟合的方程 return a * np.exp(-b * x) + c de
阅读全文
摘要:1.数据 x = np.random.uniform(-5, 5 ,size=100) X = x.reshape(-1, 1) y = x**2 + x +2 + np.random.normal(0, 1, size = 100) 2. 拟合 ploy = PolynomialFeatures(
阅读全文
摘要:使用sklearn.preprocessing.PolynomialFeatures来进行特征的构造。 它是使用多项式的方法来进行的,如果有a,b两个特征, 那么它的2次多项式为($1,a,b,a^2,ab, b^2$)。 那么它的3次多项式为($1,a,b,a^2,ab, b^2, a^3, a^
阅读全文

浙公网安备 33010602011771号