
Python
Y小星
这个作者很懒,什么都没留下…
展开
-
python启动关闭桌面应用
打开chrome:win32api.ShellExecute(0, ‘open’, R’…\chrome.exe’, ‘’, ‘’,1)关闭桌面现有chrome.exe:cmdutils.runCmd(‘TASKKILL /F /IM chrome.exe /T’)设置chrome为桌面当前应用:windowutils.set_app_top(‘Google Chrome’)原创 2023-05-12 21:55:22 · 379 阅读 · 0 评论 -
RuntimeError: The current Numpy installation fails to pass a sanity check
问题描述:RuntimeError: The current Numpy installation ('D:\\soft1\\Python37\\lib\\site-packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more information: https://tinyurl.com/y3dm3h86解决方案:原创 2020-12-19 10:36:12 · 449 阅读 · 1 评论 -
Python windows高效截屏
如下图win32系列模块是python windows api实现,效率很高,但是环境搭建比较麻烦,各种pip install报错,本次成功安装依赖idea的Alt + Enter自动下载安装def window_capture(filename): hwndDC = win32gui.GetWindowDC(0) # 0表示当前活跃的窗口 mfcDC = win32ui.CreateDCFromHandle(hwndDC) saveDC = mfcDC.CreateC.原创 2020-12-12 09:54:18 · 1643 阅读 · 1 评论 -
pyautogui效率慢优化
pyautogui为了安全的,有一个默认延迟时间0.1秒,我们可以对其进行修改来改善效率:# -*- coding: UTF-8 -*-from ctypes import windllimport timeimport pyautoguipyautogui.PAUSE = 0.005print(time.time())for i in range(20): windll.user32.SetCursorPos(900, 300) pyautogui.click()原创 2020-12-10 16:06:35 · 4425 阅读 · 1 评论 -
pip安装软件国内镜像源
临时使用:pip install pymysql -ihttps://pypi.tuna.tsinghua.edu.cn/simple 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pypi/simple/ 中国科技大学https://pypi.mirrors.ustc.edu.cn/simple/ 华中理工大学:http://pypi.hustunique.com/..原创 2020-12-10 15:01:38 · 547 阅读 · 0 评论 -
Python解析命令行参数
class CommandLineUtils: @classmethod def parser(cls, argv): command_line_params = {} try: # h后面没有冒号,表示后面不带参数; help后面没有等号,表示后面不带参数 options, args = getopt.getopt(argv, "hp:i:", ["help", "ip=", "port="]) .原创 2020-12-09 17:18:29 · 194 阅读 · 0 评论 -
Python selenium效率优化threadlocal
"""Chrome Options常用设置以下: 禁止图片和视频的加载 添加扩展:像正常使用浏览器一样的功能"""class ChromeInit: @classmethod def init(cls): options = webdriver.ChromeOptions() options.add_argument('--disable-infobars') # 禁用浏览器正在被自动化程序控制的提示 options..原创 2020-12-09 17:00:48 · 469 阅读 · 0 评论 -
Python单例模式实现方式
# 方式一:Python模块就是天然的单例模式,因为python模块只会加载一次class Singleton01: def __init__(self): passs = Singleton01()# 方式二:使用装饰器,实现原理:创建一个字典用来保存类的实例对象,然后每次创建对象的时候,都去这个字典中判断一下是否存在def singleton(cls): _instance = {} def _singleton(*args, **kwargs.原创 2020-12-09 11:53:20 · 271 阅读 · 1 评论 -
Python常用的内置函数(编译执行)
class CompileOperator(unittest.TestCase): # 将字符串编译为代码或者AST对象,使之能够通过exec或者eval语句来执行 def test_compile(self): # 流程语句使用exec str1 = "for i in range(0,10): print(i)" c1 = compile(str1, '', 'exec') exec(c1) # 简单求值.原创 2020-12-09 10:04:56 · 133 阅读 · 0 评论 -
Python常用的内置函数(变量操作)
import unittest# 定义在class、def外的是全局变量out = 'out'class VariableOperator(unittest.TestCase): # 在class里面,定义全局变量需要global关键字先申明,让程序知道该变量是全局变量,否则当普通变量处理 global inglobal inglobal = 'inglobal' # 普通变量,没被申明 inclass = 'inclass' # 返回当前作.原创 2020-12-08 16:16:14 · 166 阅读 · 0 评论 -
Python常用的内置函数(反射操作)
class Reflection(unittest.TestCase): # 检查对象是否含有属性 def test_hasattr(self): o = TestA("zhangsan") print(hasattr(o, 'name')) print(hasattr(o, 'age')) # 获取对象的属性值,如果给的属性不存在则会抛异常,所有要先判断一下该属性是否存在 def test_getattr(self):.原创 2020-12-08 15:55:22 · 166 阅读 · 0 评论 -
Python常用的内置函数(对象操作)
class ObjectOperator(unittest.TestCase): # 返回对象或者当前作用域内的属性列表 def test_dir(self): print(dir(math)) # 返回对象的唯一标识符(地址值) def test_id(self): a = 'hello world' print(id(a)) # 获取对象的哈希值 def test_hash(self): .原创 2020-12-08 15:32:41 · 300 阅读 · 0 评论 -
Python常用的内置函数(序列操作)
class SequenceOperator(unittest.TestCase): # 判断可迭代对象的每个元素是否都为True def test_all(self): print(all([1, 2])) # True print(all([0, 1, 2])) # False print(all({})) # True # 判断可迭代对象的元素是否有为True值的元素 def test_any(self): .原创 2020-12-08 15:10:33 · 273 阅读 · 0 评论 -
Python常用的内置函数(数据类型)
class DataType(unittest.TestCase): def test_boolean(self): print(bool()) # 初始化默认为False print(bool(0)) # 数值0、空序列等值为False print(bool(1)) # True def test_int(self): print(int()) # 初始化默认为0 print(int('1')) .原创 2020-12-08 14:47:20 · 269 阅读 · 0 评论 -
Python常用的内置函数(数学运算)
class MathOperator(unittest.TestCase): # 求两个数值的商和余数 def test_divmod(self): print(divmod(5.5, 2)) # 返回两个数值的商和余数 # 可迭代对象中的元素中的最值 def test_max(self): print(max(1, 2, 3)) # 取最大值 print(max('1234')) print(max(.原创 2020-12-08 11:50:20 · 459 阅读 · 0 评论 -
Python常用的内置模块简介
import hashlibimport jsonimport pickleimport subprocessimport timeimport datetimeimport randomimport osimport os.pathimport sysimport shutilimport loggingimport reimport configparserimport tracebackimport itertools原创 2020-12-08 11:27:27 · 114 阅读 · 0 评论 -
Python xlutils读写同一个Excel
xlrd:读取excel时不能对其进行其他操作xlwt:用来编辑保存excel文件xlutils:整合了xlrd和xlwt,可同时对同一文件进行读写操作原创 2020-12-08 11:25:23 · 285 阅读 · 0 评论 -
Python3.6.5文件写入中文失败
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character maps to <undefined>f = open('test.txt', 'w')f.write('你好')改成:f = codecs.open('test.txt', 'w+', 'utf-8')f.write('你好')原创 2020-12-08 11:16:57 · 297 阅读 · 0 评论