Python
Hank_Gao
失意坦然,得意淡然
展开
-
【Python】快速获取系统当前时间戳(精确到1ms)
【Python】快速获取系统当前时间戳(精确到1ms)原创 2022-12-03 11:55:48 · 806 阅读 · 1 评论 -
【Python】Python对list去重
使用list项作为键创建dict,这将自动删除任何重复项,因为dict不能有重复的键,保留原顺序。old_list = [2, 3, 4, 5, 1, 2, 3]new_list = list(dict.fromkeys(old_list))print(new_list) # [2, 3, 4, 5, 1]转载 2022-04-05 17:10:10 · 269 阅读 · 0 评论 -
【转载】Python + UIAutomator2的使用
简介uiautomator2是一个python库,用于Android的UI自动化测试,其底层基于Google uiautomator,Google提供的uiautomator库可以获取屏幕上任意一个APP的任意一个控件属性,并对其进行任意操作支持平台及语言你在python-uiautomator2封装了谷歌自带的uiautomator2测试框架,提供便利的python接口。他允许测试人员直接在PC上编写Python的测试代码,操作手机应用,完成自动化,大大提高了自动化代码编写的效率。工作原理转载 2022-03-07 16:34:43 · 5459 阅读 · 1 评论 -
【已解决】Python 3.7以上在Windows 10使用 pip install UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte
Python 3.7以上在Windows 10使用 pip install UnicodeDecodeError: 'gbk' codec can't decode byte原因解决办法参考资料#Python 3.7以上在Windows 10使用 pip install UnicodeDecodeError: ‘gbk’ codec can’t decode byte在Win 10环境下,使用pip install -U weditor报错 File "C:\Python310\lib\emai原创 2022-02-27 21:32:04 · 6233 阅读 · 5 评论 -
Python+adb自动化测试
Python+adb自动化测试软件安装软件安装Pyhton发送adb合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入软件安装软件安装1.VS Code: 链接,注意登录微软账号同步之前的设置,会自动安装插件,包括Python2.原创 2022-02-10 23:47:25 · 3439 阅读 · 0 评论 -
Python遍历处理文件
import osrootPath = r'D:\rssi'for root, dirs, files in os.walk(rootPath): for filePath in files: filePath = os.path.join(root, filePath) if filePath.find('-') > 0: pass else: print(filePath)原创 2021-08-21 22:31:39 · 183 阅读 · 0 评论 -
Python串口通信实战,计算BCC
#!/usr/bin/env python# coding=utf-8import serialimport timedef hexString2Bytes(str): str = str.replace(' ', '') return bytes.fromhex(str)def calBcc(ang1, ang2): #ang1 H, ang2 V list1 = [0, 0, 0, 0, 0, ang2] list1.append(ang1) lis原创 2021-08-21 22:30:40 · 344 阅读 · 0 评论 -
Python处理CSV,list计算标准差
#!/usr/bin/python# -*- coding: UTF-8 -*-import pandas as pdimport csvimport binasciiimport numpy as npimport osdef analysis_csv(filePath): list1 = [] with open(filePath, 'r', encoding = 'utf-8') as csvFile: #读取csv文件,返回的是迭代类型 reader1原创 2021-08-21 22:28:57 · 1059 阅读 · 0 评论 -
Python读写txt, xlsx文件实践
#!/usr/bin/env python3#-*-coding: UTF-8 -*-#Author 守望的距离import timeimport base64import openpyxlimport binasciifrom openpyxl import workbookdef decode_base64(dataIn): tempData = base64.b64decode(dataIn) bs = binascii.hexlify(bytearray(tem原创 2021-08-21 22:24:53 · 133 阅读 · 0 评论 -
Python播放音乐
Python播放音乐@TOCPython播放音乐使用pygame播放本地音乐去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.// An highlighted blockimport pygameif __name__ == '__main__': pygame.mixer.init() print("播放音乐1") track = pygame.mixer.music.load("D:\\1.wav") pygame.mixer.原创 2021-08-21 22:19:32 · 780 阅读 · 0 评论 -
Python print不换行
>>> for i in range(10): print('%3d' %i, end='') 0 1 2 3 4 5 6 7 8 9>>> data = [16, 25, 39, 27, 12, 8, 45, 63]>>> l = len(data)>>> l8>&g...原创 2020-01-30 19:03:48 · 287 阅读 · 0 评论 -
Python import
import 与 from...import在 python 用import或者from...import来导入相应的模块。将整个模块(somemodule)导入,格式为:import somemodule从某个模块中导入某个函数,格式为:from somemodule import somefunction从某个模块中导入多个函数,格式为:from somemodu...原创 2020-01-30 18:50:03 · 163 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex0 学习使用Terminal
Mac OS:-bash: /Users/myRMBP/.bash_profile: line 5: `export path=${PATH}: : 'bogon:~ myRMBP$ pythonPython 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) [GCC 4.2.1 (Apple Inc. build 5666原创 2015-10-06 20:48:09 · 606 阅读 · 0 评论 -
【Python】if语句使用规则
Rules for If-StatementsEvery if-statement must have an else.If this else should never run because it doesn't make sense, then you must use a die function in the else that prints out an error m翻译 2015-10-11 21:45:37 · 2813 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex35 通过一个简单游戏,练习循环和分支语句
from sys import exitdef gold_room(): print "This room is full of gold. How much do you take?" next = raw_input("> ") if "0" in next or "1" in next: how_much = int(next)原创 2015-10-11 21:31:20 · 1391 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex33 while循环
i = 0numbers = []while i < 6: print "At the top i is %d" % i numbers.append(i) i += 1 print "Numbers now: ", numbers print "At the bottom i is %d" % iprint "The numbers: "fo原创 2015-10-11 21:03:52 · 777 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex32 for循环
the_count = [1, 2, 3, 4, 5]fruits = ['apples', 'oranges', 'pears', 'apricots']change = [1, 'pennies', 2, 'dimes', 3, 'quarters']# this first kind of for-loop goes through a listfor number in the_原创 2015-10-11 20:55:52 · 815 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex29 if语句
people = 20cats = 30dogs = 15if people < cats: print "Too many cats! The world is doomed!"if people > cats: print "Not many cats! The world is saved!" if people < dogs: print "T原创 2015-10-11 20:35:26 · 487 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex16 读写文件
# coding:utf-8#方法1'''from sys import argvscript, filename = argvprint "We're going to erase %r." % filenameprint "If you don't want that, hit CTRL-C(^C)."print "If you do want that, hit RETUR原创 2015-10-08 21:30:48 · 600 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex10 转义字符
# coding: utf-8# 转义字符 escape sequencetabby_cat = "\tI'm tabbed in."persian_cat = "I'm split\non a line."backslash_cat = "I'm \\a \\ cat."fat_cat = """I'll do a list:\t* Cat food\t* Fishies\t原创 2015-10-07 10:28:16 · 562 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex17 文件复制
from sys import argvfrom os.path import existsscript, from_file, to_file = argvprint "Copying from %s to %s " % (from_file, to_file)# we could do these two on one line too, how?in_file = open(原创 2015-10-08 21:58:21 · 722 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex14 argv参数传值
from sys import argvscript, user_name = argvprompt = '>'print "Hi %s, I'm the %s script." % (user_name, script)print "I'd like to ask you a few questions."print "Do you like me %s?" % user_name原创 2015-10-07 14:54:12 · 477 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex9 换行符,打印多行字符
# Here's some new stange stuff, remember type it exactly.days = "Mon Tue Wed Thu Fri Sat Sun"months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"print "Here are the days: ", daysprint "Here are the原创 2015-10-07 10:09:30 · 955 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex6 格式化字符串,多行文本
x = "There are %d types of people." % 10binary = "binary"do_not = "don't"y = "Those who konw %s and those who %s." % (binary, do_not)print xprint yprint "I said: %r." % xprint "I also said: '原创 2015-10-07 08:44:13 · 486 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex3 运算符,浮点数
print "I will now count my chicken:"print "Hens", 25 + 30 / 6print "Roosters", 100 - 25 * 3 % 4print "Now i will count the eggs:"print 3 + 2 + 1 - 5 + 4 % 2 -1 / 4 + 6print "Is it true 3 + 2原创 2015-10-06 21:25:17 · 791 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex2 注释
# A comment, this is so you can read your program later.# Anything after the # is ignored by python.print "i could have code like this." # and the comment after is ignored# You can also use a com原创 2015-10-06 21:09:12 · 482 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex18 def函数
# this one is like your scripts with argvdef print_two(*args): arg1, arg2 = args print "arg1: %r ,arg2: %r" % (arg1, arg2)# ok, that *args is actually pointless, we can just do thisdef pri原创 2015-10-11 16:38:43 · 530 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex19 函数和变量
We can just give the function numbers directly:You have 20 cheeses!You have 30 boxes of crackers!Man that's enough for a party!Get a blanket. OR, we can use variables from our script:You have 1原创 2015-10-11 16:53:47 · 478 阅读 · 0 评论 -
【Python】Python实现进制转换(二进制、十进制和十六进制)及注意事项
使用内置函数实现进制转换实现比较简单,主要用到以下函数:bin()、oct()、int()、hex()下面分别详解一下各个函数的使用(附实例)第一部分:其他进制转十进制1.二进制转十进制使用函数:int()实例:123#结果是4 int('100',转载 2013-10-05 17:43:34 · 10617 阅读 · 0 评论 -
【Python】pip - 安装第三方包的神器
使用Python,肯定希望使用大量成熟的第三方包,从而快速用到自己的项目。还在一个个寻找,手动下载吗?pip就是这样一个神器,自动搜索、下载和安装第三方包:1,首先请安装pip自己,下载地址(也可以通过附件下载):http://www.pip-installer.org/en/latest/installing.html#python-os-support原创 2015-10-17 22:57:22 · 34632 阅读 · 0 评论 -
【Python】Python logging
Python内置模块logging管理不同级别log打印和存储,非常方便,从此告别了使用print打桩记录,我们来看下logging的魅力吧import logginglogging.basicConfig(level = logging.DEBUG, format = '%(asctime)s %(filename)s[line:%(lin原创 2016-04-01 23:00:09 · 768 阅读 · 0 评论 -
【Python】if __name__ == "__main__":
经常在调试Python程序时,作为入口,需要写下如下这条语句,到底这条语句是什么意思呢?Python的模块有一些内置属性,用于完成特定的任务,如__name__ , __doc__同时,每个模块都有一个名词,例如, __name__用于判断当前模块是否是程序的入口,如果当前程序正在被使用,__name__的值为“__main__”if __name__ == "__main__原创 2015-11-29 07:51:12 · 545 阅读 · 0 评论 -
使用pyinstaller打包python为exe文件
最近用python的tkinter写了个windows界面的工具,用来对软件版本发布的自动化,之前发布版本是由PHP的同事完成,又是手动上传文件到ftp,又是修改数据库,php代码等这么多繁琐的步骤。所以决定用python写了个windows的应用,因为版本发布可能会交给运营的同事完成,所以用tkinter写了个界面,顺便转换成exe的文件,之前是用py2exe,觉得不好用,搜索到了pyinsta转载 2015-11-26 22:38:22 · 737 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex50 第一个网站
利用lpthw.web框架实现"Hello World"网页版,代码如下:import weburls = ('/', 'index')app = web.application(urls, globals())render = web.template.render('templates/')class Index: def GET(self): gr原创 2015-11-23 21:26:05 · 1932 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex39 字典操作
# create a mapping of state to abbreviationstates = { 'Oregon': 'OR', 'Florida': 'FL', 'California': 'CA', 'New York': 'NY', 'Michigan': 'MI'}# create a basic set of states and原创 2015-10-14 22:55:42 · 724 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex26 修改代码错误
#coding:utf-8#修改后的代码如下import ex25def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wordsdef sort_words(words): """Sorts the原创 2015-10-11 20:07:55 · 915 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex25 函数综合练习
def break_words(stuff): """This function will break up words for us.""" words = stuff.split(" ") return words def sort_words(words): """Sorts the words.""" return sorted(words原创 2015-10-11 19:33:11 · 705 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex24 函数综合练习
#coding:utf-8print "Let's practice everything."print "You\'d need to konw \'bout escapes with \\ that do \n newlines and \t tabs."poem = '''\tThe lovely worldwith logic so firmly plantedcannot原创 2015-10-11 18:02:40 · 802 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex21 函数返回值return
def add(a, b): print "ADDING %d + %d" % (a, b) return a + b def subtract(a, b): print "SUBTRACTING %d - %d" % (a, b) return a - b def multiply(a, b): print "MULTIPLYING %原创 2015-10-11 17:30:16 · 544 阅读 · 0 评论 -
【Python】Learn Python the hard way, ex20 用函数读文件readline
from sys import argvscript, input_file = argvdef print_all(f): print f.read() def rewind(f): f.seek(0) def print_a_line(line_count, f): print line_count, f.readline() cu原创 2015-10-11 17:09:34 · 578 阅读 · 0 评论