【foo.py】# encoding: utf-8 # author: walker # date: 2019-07-15 # summary: 一种正则和 lambda 的有趣结合 import re dic = {'user': 'walker', 'domain': '163.com'} rule = r'%user%@%domain%' email = re.sub('%[^%]*%'
【code】#encoding: utf-8 #author: walker #date: 2019-05-24 #summary: 简单的 http server,用于测试后台运行 import http.server import socketserver PORT = 5678 Handler = http.server.SimpleHTTPRequestHandler with s
【PyExecJS】#encoding: utf-8 #author: walker # date: 2019-03-13 # summary: 利用 PyExecJS 调用 js 函数 import execjs JSCode = r'''
【情形一】OS 版本:Windows 10 x64Python 版本:3.6.5 x64pip3 版本:下载命令pip3 download regex -d ./lib安装命令pip3 install ./lib/regex-2018.11.22-cp36-none-win_amd64.whl【相关阅读】pip download*** w
【吐槽】 先吐槽一下其他几个配置文件。ini:表达能力不够,比如不能表达列表等结构;没有官方注释符号,虽然一般以分号作为注释符号。json:没有官方注释符号,虽然某些第三方包提供了注释结构。yaml:语法比较复杂,可读性不太高。【toml 简介】 TOML是前GitHub CEO, Tom Preston-Werner,于2013年创
【背景】 截至 Python 3.6.6,concurrent.futures.ThreadPoolExecutor 中用的都是无·界队列,在生产速度大于消费速度时,可能会耗光系统资源,希望找到一种方式避免这种情况。【方案一】继承 ThreadPoolExecutor,直接修改 _work_queue 为有界队列。优点:简单粗暴直接。缺点:修改了私有属性
本程序遍历 ftp 目录,列出单个文件大小,统计目录个数、文件个数、文件总大小。目的是在批量下载 FTP 文件时,不严格的验证下载结果的正确性。
【问题简述】 在 Linux 下后台执行 Python 脚本,重定向到日志文件,日志文件迟迟没有内容。【方案一】(测试有效)nohup python3 -u t.py &> log.log &【方案一】(测试无效) 方案二来自 stackoverflow,虽然测试无效,但其他地方
常用函数 查找子控件 发送快捷键
控制日志同时输出到控制台和日志文件,两种输出可以有不同的日志等级
【背景】 Windows 的记事本会给 UTF-8 文件添加 BOM 头,很烦,搞个通用的读取配置文件的代码。【config.ini】[config] SrcRoot=D:\input DstRoot=D:\output【t.py】#encoding=utf-8 #author: walker #date: 2018-03-31 #summary: 读取
查看 MSC 版本>>> import sys >>> sys.version '3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (A
XMLProcessingModules深入解读Python解析XML的几种方式XML元素顺序何时重要python中lxml模块生成xml文件(顺序问题)
环境Windows10Python3.6.3pywin32地址:https://sourceforge.net/projects/pywin32/files/pywin32/具体方法cd...\Python36\Lib\site-packages\win32com\clientpythoncombrowse.py示例相关阅读howtogetattributesfromwin32com.client
【测试环境】os:Windows 10 x64 Python:3.6.3【server.py】#encoding: utf-8 #author: walker #date: 2017-12-01 #summary: 用socket创建tcp server以接收文件 import o
Python3 中 str 与 bytes 的转换:The bytes/str dichotomy in Python 3字符与 Unicode 编号之间的转换# 字符转 Unicode 编号 >>> ord('A') 65 >>> hex(ord('A')) '0x41&
代码速记:#encoding: utf-8 #author: walker #date: 2017-07-24 #summary: 回显http头,可用于匿名度检测 #sys.version: '3.5.2 (default, Nov 17 2016, 17:05:23) \n[G
#encoding: utf-8 #author: walker #date: 2017-06-15 #summary: 自定义文件夹处理函数,适用于python3.5+ import os import shutil import win32com.client #清空目录 def ClearDir(dir):
在python3中使用密钥文件方式的ssh。#encoding: utf-8 #author: walker #date: 2017-03-29 #summary: 在python代码中使用ssh #Python sys.version 3.6.1 (v3.6.1:69c0db5, Mar 21
1、tempfile — 产生临时文件和目录。2、StringIO — 在内存中读写文本文件。3、BytesIO — 在内存中读写二进制文件。相关阅读:tmpfs小结*** walker ***
1、获取进程ID。(getpid)os.getpid()2、获取父进程ID。(getppid)os.getppid()3、获取线程ID。(get_ident)(1)、进程内局部标识。import threading threading.get_ident() threading.current_thread().ident(2)、系统全局标识:python下使用ctypes获取threa
code say:#encoding=utf-8 #author: walker #date: 2016-06-28 #summary: 编译当前文件夹下所有.py文件 import os, sys, shutil import py_compile cur_dir_fullpath = os.path.
【效果图】 walker喜欢的功能:代码补全,一个问号(?)给出注释,两个问号浏览代码。【环境】 Windows7 x64,Python 3.5。【步骤】安装ipython。pip3 install ipython -i https://pypi.doubanio.com/simple/安装pyreadline。pip3 i
1、一些库的汇总信息:https://wiki.python.org/moin/WebServices 2、walker主要试用了suds 和 zeep,walker的Python版本为3.5.1。【suds】 pip3 install suds 会报 ImportError: No module named client 这个错误。 查阅信息后用 pi
1、由于PEP 488建议淘汰pyo文件,下面不再赘述。2、编译单文件。python -m py_compile test.py3、编译目录下的文件。python -m compileall D:\test相关阅读:1、py_compile 2、compileall — Byte-compile Python libraries
1、获取url参数。>>> from urllib import parse >>> url = r'https://docs.python.org/3.5/search.html?q=parse&check_keywords=yes&area=default'
【方式一】百分号(%)方式,类C的printf,需要分别不同类型。1、匿名tuple。(推荐在参数少时用)>>> '姓名:%s, 年龄:%d' % ('walker', 99) '姓名:walker, 年龄:99'2、命名dict,字典的key可以重用。>>> '姓名:%(name)s,&nb
1、根据文件头。#是否为带BOM头的UTF8文件 def IsUtf8BomFile(pathfile): if b'\xef\xbb\xbf' == open(pathfile, mode='rb').read(3)): return True return False2、用cchardet库。>>&
code say anything:#encoding=utf-8 #author: walker #date: 2016-03-07 #summary: 获取自己的外网IP import requests from bs4 import BeautifulSoup #获取外网IP def GetOuterIP()
walker经常用到当前时间和相对时间,用来统计程序执行的效率,简单记一下,便于copy。>>> import time #相对时间 >>> startTime = time.time() >>> '%.2fs' % (time.time()&
Copyright © 2005-2024 51CTO.COM 版权所有 京ICP证060544号