随笔分类 -  python相关

摘要:class A: _variable_one_class = '_variable_one_class' __variable_two_class = '__variable_two_class' def __init__(self): self._variable_one = '_variable 阅读全文
posted @ 2023-10-03 00:56 Orientation 阅读(124) 评论(0) 推荐(0) 编辑
摘要:def initial_log(self, fileName, logName, level=logging.INFO, fileSize=1024): handler = RotatingFileHandler(fileName + '.log', maxBytes=1 * fileSize * 阅读全文
posted @ 2023-08-30 21:24 Orientation 阅读(9) 评论(0) 推荐(0) 编辑
摘要:time 模块 time 模块下三种时间格式: stamptime 时间戳 ,常用的time.time() 返回的就是一个时间戳 1659513403.53 format time eg 2984-01-15 16:31:20 time tuple eg time.struct_time(tm_ye 阅读全文
posted @ 2022-08-03 16:41 Orientation 阅读(65) 评论(0) 推荐(0) 编辑
摘要:pip 是 Python 包管理工具,该工具提供了对Python 包的查找、下载、安装、卸载的功能。 目前如果你在 python.org 下载最新版本的安装包,则是已经自带了该工具。 注意:Python 2.7.9 + 或 Python 3.4+ 以上版本都自带 pip 工具。 pip 官网:htt 阅读全文
posted @ 2022-07-27 20:16 Orientation 阅读(512) 评论(0) 推荐(0) 编辑
摘要:python 3.x import pymysql conn=pymysql.connect(host,port,user,passwd,database,chartset)cursor=conn.cursor()row_count=cursor.execute('show databases;') 阅读全文
posted @ 2022-07-13 20:06 Orientation 阅读(25) 评论(0) 推荐(0) 编辑
摘要:通过 dir 方法 可以查看 dir(obj) 如果是自定义类生成的对象,可以通过 __dict__ 属性来查看, class Test(): ''' this is document ''' x=1 def __init__(self,name,age): self.name=name self. 阅读全文
posted @ 2022-07-13 10:44 Orientation 阅读(274) 评论(0) 推荐(0) 编辑
摘要:socket 实现 tcp server import socket soc=socket.socket() #默认 family=-1,type=-1, proto=-1, fileno=None ''' if fileno is None: if family == -1: family = A 阅读全文
posted @ 2022-07-12 20:00 Orientation 阅读(251) 评论(0) 推荐(0) 编辑
摘要:import serial ser= serial.Serial('/dev/ttyAMA0',9600)ser.write('hello world'.encode('ascii'))data_len = ser.inWaiting()ser.read(data_len) 阅读全文
posted @ 2022-07-12 19:28 Orientation 阅读(452) 评论(0) 推荐(0) 编辑
摘要:openpyxl 用法实例 import requests import openpyxl import json import time res = requests.request('GET', 'http://1.2.32.2:23/data/getsites') text = res.tex 阅读全文
posted @ 2022-07-12 19:24 Orientation 阅读(33) 评论(0) 推荐(0) 编辑
摘要:通过 os 模块实现import os result = os.system('ssh localhost -p7021')#现场机做过远程登陆 ''' def system() #Execute the command in a subshell pass ''' os.system 方法本质上是 阅读全文
posted @ 2022-01-21 18:48 Orientation 阅读(601) 评论(0) 推荐(0) 编辑
摘要:基于 python 3 跳板机和目标机处于同一内网,在外网仅可访问跳板机, import pymysql as mysql from sshtunnel import SSHTunnelForwarder server = SSHTunnelForwarder(('IP', 'PORT'), # 跳 阅读全文
posted @ 2022-01-19 22:25 Orientation 阅读(91) 评论(0) 推荐(0) 编辑
摘要:各种进制数的表示方法 #二进制 0b100101 #八进制 python2中可以以0开头 eg:070560o705 python3 zhong 0o开头的才是8进制 eg 0o7056 #十进制 999 #十六进制 0xFE int() #不带参数,只能对数字转换 a = 0xF01 b = in 阅读全文
posted @ 2021-12-28 11:03 Orientation 阅读(992) 评论(0) 推荐(0) 编辑
摘要:新增粉尘仪检测设备调试中需要对 hex 32位浮点数 转10 进制小数(保留三位小数) def ieee_transfer(hex_str): """ :param hex_str: hex string like '4145851F' :return: float type """ ret = ' 阅读全文
posted @ 2021-11-24 19:05 Orientation 阅读(680) 评论(0) 推荐(0) 编辑
摘要:CRC16 python实现 crc16_IBM def crc16_IBM(data): # parameter data :'01 00 00 80 00 00 00 ..... 00 ce c2 b6 c8 33 38 32 35 a1 e6' if isinstance(data, str) 阅读全文
posted @ 2021-11-22 16:08 Orientation 阅读(1138) 评论(0) 推荐(0) 编辑
摘要:客户端 # -*- coding: UTF-8 -*- import socket import time socket.setdefaulttimeout(10) # 设置socket 接收超时 s = socket.socket() s.connect_ex(('101.37.*.*', 900 阅读全文
posted @ 2021-11-22 13:32 Orientation 阅读(33) 评论(0) 推荐(0) 编辑
摘要:_var :一个下划线开头,一般用来声明是内部变量,可以被继承,在模块或类外可以但不建议调用 __var: 前置双下划线,私有化属性或方法,不能被继承,只有内部可以访问,外部访问报错 __var__:以双下划线开头,并且以双下划线结尾的,是特殊变量(这就是在python中强大的魔法方法),特殊变量是 阅读全文
posted @ 2021-11-19 15:49 Orientation 阅读(65) 评论(0) 推荐(0) 编辑
摘要:logging模块是Python内置的标准模块,主要用于输出运行日志,可以设置输出日志的等级、日志保存路径、日志文件回滚等; 1. 控制台基本使用: import logging logging.basicConfig(level = logging.INFO,format = '%(asctime 阅读全文
posted @ 2021-10-30 17:37 Orientation 阅读(191) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示