随笔分类 -  Python

1 2 3 4 5 ··· 15 下一页
Python zone
摘要:import socket try: # 你的socket代码,例如创建一个连接 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('localhost', 8080)) except socket.timeout: p 阅读全文
posted @ 2025-03-03 15:56 西北逍遥 阅读(14) 评论(0) 推荐(0) 编辑
摘要:(base) bim@bim-Smart-Client:~/Anaconda$ (base) bim@bim-Smart-Client:~/Anaconda$ (base) bim@bim-Smart-Client:~/Anaconda$ conda create -n wind_2025 pyth 阅读全文
posted @ 2025-01-11 15:36 西北逍遥 阅读(10) 评论(0) 推荐(0) 编辑
摘要:import time import math import numpy as np # A small helper function to limit angles between -pi and pi def wrap_to_pi(angle): while angle > math.pi: 阅读全文
posted @ 2025-01-11 10:21 西北逍遥 阅读(8) 评论(0) 推荐(0) 编辑
摘要:VTK环境 (base) C:\Users\BIM> (base) C:\Users\BIM>conda create -n vtk_env python==3.8 Collecting package metadata (current_repodata.json): done Solving e 阅读全文
posted @ 2024-12-10 07:43 西北逍遥 阅读(11) 评论(0) 推荐(0) 编辑
摘要:# -*- coding: utf8 -*- import serial import time import datetime import struct # 替换成你的串口名称和波特率 ser = serial.Serial('COM5', 115200, timeout=1) def anal 阅读全文
posted @ 2024-09-13 15:30 西北逍遥 阅读(21) 评论(0) 推荐(0) 编辑
摘要:ImageDraw.Draw 填充区域 在Python的PIL(Python Imaging Library,现在通常称为Pillow)库中,ImageDraw.Draw 对象用于在图像上绘制形状。要填充一个区域,你通常会使用 rectangle、ellipse、polygon 等方法,并指定填充颜 阅读全文
posted @ 2024-08-30 19:12 西北逍遥 阅读(114) 评论(0) 推荐(0) 编辑
摘要:python 计算list的方差 import numpy as np # 假设我们有一个包含数值的列表 data = [1, 2, 3, 4, 5] # 计算均值 mean = np.mean(data) # 计算方差 variance = np.var(data) # 这将使用默认的N-1作为分 阅读全文
posted @ 2024-08-21 18:12 西北逍遥 阅读(195) 评论(0) 推荐(0) 编辑
摘要:python获取当前日期 年月日时分秒 from datetime import datetime now = datetime.now() current_time = now.strftime("%Y-%m-%d %H:%M:%S") ############################## 阅读全文
posted @ 2024-08-13 22:05 西北逍遥 阅读(243) 评论(0) 推荐(0) 编辑
摘要:pyqt5 combox选择事件绑定 import sys from PyQt5.QtWidgets import QApplication, QWidget, QComboBox, QVBoxLayout, QLabel class ComboBoxExample(QWidget): def __ 阅读全文
posted @ 2024-08-12 15:13 西北逍遥 阅读(167) 评论(0) 推荐(0) 编辑
摘要:python 读取文本文件 # 打开文件 with open('myfile.txt', 'r') as file: # 读取文件内容 content = file.read() # 打印文件内容 print(content) ########################## 阅读全文
posted @ 2024-08-10 19:38 西北逍遥 阅读(14) 评论(0) 推荐(0) 编辑
摘要:python 逐行读取文本文件 # 打开文件 with open('myfile.txt', 'r') as file: # 逐行读取文件内容 for line in file: print(line, end='') # 注意,print 函数默认会在每行末尾添加换行符,所以这里使用 end='' 阅读全文
posted @ 2024-08-07 20:22 西北逍遥 阅读(23) 评论(0) 推荐(0) 编辑
摘要:python 写入文本文件 # 打开文件,如果文件不存在则创建它 with open('myfile.txt', 'w') as file: # 写入内容 file.write('kkkkkkkkkkkkkkkkkkk!\n') ################################### 阅读全文
posted @ 2024-08-06 18:48 西北逍遥 阅读(22) 评论(0) 推荐(0) 编辑
摘要:python 追加到文本文件 # 打开文件以追加内容 with open('myfile.txt', 'a') as file: # 追加内容 file.write('kkkkkkkkkkkkkkkkkkkkk.\n') ################################# 阅读全文
posted @ 2024-08-03 19:35 西北逍遥 阅读(14) 评论(0) 推荐(0) 编辑
摘要:python 修改文本文件 # 读取文件内容 with open('myfile.txt', 'r') as file: content = file.read() # 修改内容(这里只是一个简单的替换示例) modified_content = content.replace('old_text' 阅读全文
posted @ 2024-07-30 18:53 西北逍遥 阅读(35) 评论(0) 推荐(0) 编辑
摘要:python 读取CSV文件 import csv # 打开CSV文件 with open('example.csv', 'r', newline='') as file: reader = csv.reader(file) # 遍历CSV文件的每一行 for row in reader: prin 阅读全文
posted @ 2024-07-29 16:52 西北逍遥 阅读(9) 评论(0) 推荐(0) 编辑
摘要:python 写入CSV文件 import csv # 定义要写入CSV文件的数据 data = [ ['Name', 'Age', 'City'], ['Alice', '25', 'New York'], ['Bob', '30', 'San Francisco'], # ... ] # 打开C 阅读全文
posted @ 2024-07-28 15:56 西北逍遥 阅读(24) 评论(0) 推荐(0) 编辑
摘要:python 读取CSV文件 import csv # 打开CSV文件 with open('example.csv', 'r', newline='') as file: reader = csv.DictReader(file) # 遍历CSV文件的每一行(作为字典) for row in re 阅读全文
posted @ 2024-07-27 23:19 西北逍遥 阅读(15) 评论(0) 推荐(0) 编辑
摘要:python 使用字典写入CSV文件 import csv # 定义要写入CSV文件的数据(作为字典列表) data = [ {'Name': 'Alice', 'Age': '25', 'City': 'New York'}, {'Name': 'Bob', 'Age': '30', 'City' 阅读全文
posted @ 2024-07-26 23:04 西北逍遥 阅读(189) 评论(0) 推荐(0) 编辑
摘要:python两个三阶矩阵相乘 import numpy as np matrix1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) matrix2 = np.array([[9, 8, 7], [6, 5, 4], [3, 2, 1]]) result = 阅读全文
posted @ 2024-07-25 23:31 西北逍遥 阅读(11) 评论(0) 推荐(0) 编辑
摘要:python numpy 1x3的矩阵乘3x3的矩阵 import numpy as np # 创建1x3的矩阵A A = np.array([[1, 2, 3]]) # 创建3x3的矩阵B B = np.array([[4, 5, 6], [7, 8, 9], [10, 11, 12]]) # 矩 阅读全文
posted @ 2024-07-15 21:15 西北逍遥 阅读(35) 评论(0) 推荐(0) 编辑

1 2 3 4 5 ··· 15 下一页
点击右上角即可分享
微信分享提示