![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
sha_ka
这个作者很懒,什么都没留下…
展开
-
关于python的time
【代码】关于python的time。原创 2022-11-14 14:38:24 · 534 阅读 · 1 评论 -
python所有字节码
import opcodefor i, j in enumerate(opcode.opname): print("0x%2x(%03d): %s" % (i, i, j))原创 2020-04-16 11:40:24 · 193 阅读 · 0 评论 -
python字节码
参考:https://bbs.pediy.com/thread-246683.htm原创 2020-04-16 11:28:34 · 132 阅读 · 0 评论 -
python zip函数的高级用法,消耗迭代器/生成器
In [1]: a = (i for i in range(10))In [2]: aOut[2]: <generator object <genexpr> at 0x0000027493A53190>In [5]: In [4]: for i in zip(*[a]*2): ...: print(i) ...:(0, 1)(2, 3)...原创 2020-03-24 16:22:09 · 427 阅读 · 0 评论 -
python3 read readline和readlines详解
我们学习python基础的时候都知道,python 文件读取有三个常用方法:readreadlinereadlines方法无参数有参数read读取整个文件直到文件末尾读取固定大小字节(byte)数readline读取整个文件的一行一直读取直到遇到\n 返回所读的整行数据读取文件固定大小的字节数返回字符串readlines读取整个文件,返回值放...原创 2020-02-12 13:03:57 · 2164 阅读 · 0 评论 -
数据描述符
实现了__get__、__set__、__delete__中任意一个方法的类,称之为属性描述符。实现了__get__、__set__、__delete__中任意一个方法的类,称之为属性描述符。属性描述符可以控制属性操作时的一些行为。只要具有__get__方法的类就是描述符类。如果一个类中具有__get__和__set__两个方法,那么就是数据描述符。如果一个类中只有__get__方法,那...转载 2020-01-20 14:46:49 · 484 阅读 · 0 评论 -
Python正则表达式中的re.S,re.M,re.I的作用
正则表达式可以包含一些可选标志修饰符来控制匹配的模式。修饰符被指定为一个可选的标志。多个标志可以通过按位 OR(|) 它们来指定。如 re.I | re.M 被设置成 I 和 M 标志:修饰符描述re.I使匹配对大小写不敏感re.L做本地化识别(locale-aware)匹配re.M多行匹配,影响 ^ 和 $re.S使 . 匹配包括换行在内的所有字符...转载 2019-11-27 14:46:38 · 253 阅读 · 0 评论 -
python 多层装饰器加载和执行顺序
加载顺序(outter函数的调用顺序):自下而上执行顺序(wrapper函数的执行顺序):自上而下def outter1(func1): # func1=wrapper2的内存地址 print('加载了outter1') def wrapper1(*args, **kwargs): print('执行了wrapper1') res1 = ...转载 2019-11-20 15:00:09 · 304 阅读 · 0 评论 -
python 对象转字典
https://blog.csdn.net/little_stupid_child/article/details/80975237https://blog.csdn.net/weixin_42359464/article/details/80882549原创 2019-04-22 21:32:46 · 466 阅读 · 0 评论 -
python项目目录结构
ProjectName/|---README |----LICENSE |----setup.py |-----requirements.txt |------sample/ | |----__init__.py | |----core.py | |----helpers.py |------docs/ |...原创 2019-02-14 09:39:10 · 1014 阅读 · 0 评论 -
嵌套列表展开
方法一:使用列表推导式&gt;&gt;&gt; vec = [[1,2,3],[4,5,6],[7,8,9]]&gt;&gt;&gt; get = [num for elem in vec for num in elem]&gt;&gt;&gt; get[1, 2, 3, 4, 5, 6, 7, 8, 9]方法二:使用sum函数&原创 2019-02-12 17:56:39 · 415 阅读 · 0 评论 -
正则贪婪匹配例子
正则贪婪匹配 又称为正则最大匹配非贪婪匹配 又称正则最小匹配In [1]: import reIn [2]: s = "<a>哈哈</a><a>hehe</a>"In [3]: res1 = re.findall("<a>(.*)</a>",s)In [4]: res2 = re.fin原创 2019-02-12 17:06:49 · 134 阅读 · 0 评论 -
python 标准库
核心模块1.1. 介绍1.2. _ builtin _ 模块1.3. exceptions 模块1.4. os 模块1.5. os.path 模块1.6. stat 模块1.7. string 模块1.8. re 模块1.9. math 模块1.10. cmath 模块1.11. operator 模块1.12. copy 模块1.13. sys 模块1.14. ate...原创 2019-02-22 22:05:32 · 437 阅读 · 0 评论 -
python3 中的 bytes 和 bytearray 以及他们之间的差别
python3 中的 bytes 和 bytearray 以及他们之间的差别本文结果是: bytes 是不可变的 bytearray 是可变的,就类似 元组 和 列表的关系。如果读者只是为了寻找答案,那么。读完这句话就可以离开本页面了。bytes创建方式:英文字符串前边加上 b使用数字的数组创建 PS: bytes 本质上就是 数字 “数组”In [1]: b = b'A b...原创 2019-06-24 14:59:29 · 1719 阅读 · 0 评论 -
Python 常用的标准库以及第三方库
作者:史豹链接:https://www.zhihu.com/question/20501628/answer/223340838来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。Python常用库大全,看看有没有你需要的。环境管理管理 Python 版本和环境的工具p – 非常简单的交互式 python 版本管理工具。pyenv – 简单的 Python...转载 2019-02-22 21:48:55 · 1074 阅读 · 0 评论 -
Python 资源大全中文版
Python 资源大全中文版我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列的资源整理。awesome-python 是 vinta 发起维护的 Python 资源列表,内容包括:Web框架、网络爬虫、网络内容提取、模板引擎、数据库、数据可视化、图片处理、文本处理、自然语言处理、机器学习、日志、代码分析等。由伯乐在线持续更新。Awesome 系列虽然挺全,但基本...原创 2019-04-20 09:56:48 · 504 阅读 · 0 评论 -
python描述符
https://www.cnblogs.com/Jimmy1988/p/6808237.html转载 2019-05-08 14:10:27 · 97 阅读 · 0 评论 -
python 魔法方法 __setattr__,__getattr__,__getattribute__
https://www.cnblogs.com/big-handsome-guy/p/8618078.html转载 2019-05-07 09:52:57 · 134 阅读 · 0 评论 -
Python 中的单例模式
https://www.cnblogs.com/huchong/p/8244279.html转载 2019-10-10 19:42:55 · 95 阅读 · 0 评论 -
SmallPython代码
SmallPython 完整代码#include<iostream>#include<string.h>#include<iterator>#include<stdlib.h>#include<stdio.h>#include<memory>#include<map>#include<ctyp...原创 2019-09-29 09:59:27 · 427 阅读 · 0 评论 -
logging 模块
logging 模块日志级别: debug —> info —> warning —> error —> critical形式从可预期不紧急信息,到不可预期严重紧急错误。In[1]:import loggingIn[2]:logging.debug("debug message") # 告警级别最低,编程时会用到。In[3]:logging.info("...原创 2019-09-10 14:33:15 · 141 阅读 · 0 评论 -
python实现udp服务器端和客户端 echoserver
UDPserver创建过程:创建一个UDP 的socket绑定地址和端口号 (地址, 端口号) 注意参数是元组形式开始收发 loopimport socketudp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # AF_INET 表示使用IPv4, SOCK_DGRAM 则表明数据将是数据报(datagrams),...原创 2019-06-21 15:27:19 · 2412 阅读 · 0 评论 -
python实现tcp服务与客户端 echoserver
TCPserver服务端创建步骤:创建一个 socket 连接 参数默认不填就是 TCP 连接绑定地址和端口号注意是一个元组(主机名/地址, 端口号)准备监听连接 ,5表示可以接受客户端的连接数量,多余的会阻塞 不过这些多线程才有效接受客户端连接发送和接收数据 (loop: 注意收是成对的 服务端有接收,那么客户端对应的也有发送)"""# filename: tcp_serv...原创 2019-06-21 15:14:05 · 913 阅读 · 0 评论 -
巧用partial,简化带参数装饰器
from functools import wraps, partialimport loggingdef logged(func=None, *, level=logging.DEBUG, name=None, message=None): if func is None: return partial(logged, level=level, name=name...原创 2019-05-13 10:57:37 · 160 阅读 · 0 评论 -
python 特殊方法解释与简单使用示例
C.__init__(self[, arg1, ...]) 构造器(带一些可选的参数)C.__new__(self[, arg1, ...]) 构造器(带一些可选的参数)通常用在设置不变数据类型的子类。C.__del__(self) 析构器C.__str__(self) 可打印的字符输出;内建str()及print 语句C.__repr__(self) 运行时的字符串输出 内建repr()...原创 2018-12-20 11:33:25 · 143 阅读 · 0 评论 -
python 特殊方法
类别方法名字符串/字节序列表示形式__repr__、__str__、__format__、__bytes__数值转换__abs__、__bool__、__complex__、__int__、__float__、__hash__、__index__集合模拟__len__、__getitem__、__setitem__、__delitem__、__contains...原创 2018-12-20 11:30:38 · 320 阅读 · 0 评论 -
python 属性查找过程
python 属性查找过程如果 user 是某个累的实力,那么 user.age (以及等价的getattr(user,‘age’)) 首先会调用 __getattribute__ 。如果定义的__getattr__ 方法,那个在 __getattribute__ 抛出 AttrbuteError 的时候会调用 __getattr__ ,为对于描述符 __get__ 的调用,则是发生在 __g...原创 2018-12-24 21:54:24 · 219 阅读 · 0 评论 -
python 简单模拟stack
class Stack: __slots__ = ('__items') def __init__(self): '''初始化栈为空列表''' self.__items = [] def is_empty(self): """判断是否为空栈, 返回 bool 值""" return self.__items == [] def peek(self): """查看栈顶...原创 2019-01-29 16:22:54 · 145 阅读 · 0 评论 -
Python对象的循环引用问题
https://www.cnblogs.com/Leon-The-Professional/p/10137405.html转载 2019-02-05 07:50:10 · 781 阅读 · 0 评论 -
字符串格式化&数字进制转换
In [1]: x = 1234.56789In [2]: format(x, '0.2f') # Two decimal place of accuracyOut[2]: '1234.57'In [3]: format(x, '>10.1f') # Right justified in 10 chars, # one-digit accuracyOut[3]: ' ...原创 2019-01-28 16:51:56 · 213 阅读 · 0 评论 -
python巧用lambda
疑惑来自 django 源码:request.user = SimpleLazyObject(lambda: get_user(request))In [3]: def add(): ...: return 1+2 ...:In [4]: a = lambda:add()In [5]: aOut[5]: <function __main__.<lam...原创 2019-01-21 11:37:26 · 149 阅读 · 0 评论 -
魔术方法调用解释
魔术方法调用方式解释_new_(cls [,…])instance = MyClass(arg1, arg2)_new_ 在创建实例的时候被调用_init_(self [,…])instance = MyClass(arg1, arg2)_init_ 在创建实例的时候被调用_cmp_(self, other)self == other, self >...原创 2019-01-02 13:03:05 · 262 阅读 · 0 评论 -
super() 的 __init__、__new__、__call__
注意:super 的 __init__ 和 __call__ 第一个参数去掉,__new__ 的不能去掉def __init__(self, *args, **kwargs): print "init" super(O, self).__init__(*args, **kwargs) def __new__(cls, *args, **kwargs): print "...原创 2019-01-11 10:45:03 · 620 阅读 · 0 评论