随笔分类 -  python高级知识

摘要:使用方法 # 自定义对象序列化的时候使用 class Demo: def __init__(self, name, age=0): self.name = name self.age = age def __str__(self): return f"name: {self.name}\nage: 阅读全文
posted @ 2021-10-20 17:41 该显示昵称已被使用了 阅读(237) 评论(0) 推荐(0)
摘要:代码 # wraps的参数是原来的函数,修饰返回的函数 def _implicit_lookup(self, subroutine, arg_name): # feed 里面查找 animal replacer = ArgumentReplacer(subroutine, arg_name) @wr 阅读全文
posted @ 2021-07-20 17:20 该显示昵称已被使用了 阅读(170) 评论(0) 推荐(0)
摘要:子类调用父类的方法 # 1 class SSHConnectionCache(ConnectionCache): def __init__(self): ConnectionCache.__init__(self, no_current_msg='No open connection.') # 2 阅读全文
posted @ 2021-06-22 11:06 该显示昵称已被使用了 阅读(50) 评论(0) 推荐(0)
摘要:获取python版本 PY_VERSION = sys.version_info[:3] PY2 = PY_VERSION[0] == 2 PY3 = not PY2 定义python不同版本的处理 if PY2: # io.StringIO only accepts u'foo' with Pyt 阅读全文
posted @ 2021-06-17 11:18 该显示昵称已被使用了 阅读(79) 评论(0) 推荐(0)
摘要:https://zhuanlan.zhihu.com/p/47124891 和装饰器一样,它可以扩展函数的功能,但又不完成等价于装饰器。通常应用的场景是当我们要频繁调用某个函数时,其中某些参数是已知的固定值,通常我们可以调用这个函数多次, 但这样看上去似乎代码有些冗余,而偏函数的出现就是为了很少的解 阅读全文
posted @ 2021-06-09 17:11 该显示昵称已被使用了 阅读(58) 评论(0) 推荐(0)
摘要:方法1 class C1: def __init__(self): self._x = None def getx(self): print('getx') return self._x def setx(self, value): print('setx') self._x = value def 阅读全文
posted @ 2021-06-08 16:44 该显示昵称已被使用了 阅读(42) 评论(0) 推荐(0)
摘要:结论【is不适合来判断两个字符串是否相等】 相对于较小的字符串,Python为了提高性能会保留其值的一个副本,当你再次创建这个字符串的时候,直接就指向了这个副本,所以'hello'这个字符串是在内存中有一个副本的,所以a和b的id的值是一样的; 而a1和b1是长字符串,并不会驻留,Python在内存 阅读全文
posted @ 2021-05-28 09:50 该显示昵称已被使用了 阅读(72) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/lovesqcc/p/8087510.html 修改前 def commonGenerate(startTime, endTime, field, values): reqs = [] for val in values: requestId = st 阅读全文
posted @ 2021-05-09 11:03 该显示昵称已被使用了 阅读(28) 评论(0) 推荐(0)
摘要:使用next() def foo(): print("starting...") while True: res = yield 4 # yield 在等式的右边,执行完就返回了,没有进行赋值 ;类似于 a = return 1【return这样用非法】,a 是NONE print("res:",r 阅读全文
posted @ 2021-04-15 10:14 该显示昵称已被使用了 阅读(718) 评论(0) 推荐(1)
摘要:定义 if PY2: # io.StringIO only accepts u'foo' with Python 2. from StringIO import StringIO def py2to3(cls): if hasattr(cls, '__unicode__'): cls.__str__ 阅读全文
posted @ 2021-04-06 15:31 该显示昵称已被使用了 阅读(59) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/liaohuiqiang/p/7247393.html 概述 # 1 # coding:utf-8 # 开头的encoding是对于文件内容的编码 # 2 import sys reload(sys) sys.setdefaultencoding('u 阅读全文
posted @ 2021-04-04 12:04 该显示昵称已被使用了 阅读(137) 评论(0) 推荐(0)
摘要:https://zhuanlan.zhihu.com/p/88048361 https://pythonav.com/wiki/detail/6/88/ 阅读全文
posted @ 2021-04-02 06:37 该显示昵称已被使用了 阅读(78) 评论(0) 推荐(0)
摘要:https://mp.weixin.qq.com/s/FjR0K5LGKoLHi4JsRqj02A https://pythonav.com/wiki/detail/6/88/ Python的赋值语句:a=1 整数1为一个对象。而a是一个引用。利用赋值语句,引用a指向对象1。Python是动态类型的 阅读全文
posted @ 2021-04-01 11:07 该显示昵称已被使用了 阅读(90) 评论(0) 推荐(0)
摘要:类的内部创建实例,这两种方法的区别 class Foo(object): def create_new(self): return self.__class__() def create_new2(self): return Foo() class Bar(Foo): pass b = Bar() 阅读全文
posted @ 2021-03-31 15:11 该显示昵称已被使用了 阅读(86) 评论(0) 推荐(0)
摘要:这个文章不错 https://www.waynerv.com/posts/python-descriptor-in-detail/ Clean Code in Python中的描述符类学习 # 具有当前城市的旅行者在程序运行期间跟踪用户访问过的所有城市 class HistoryTracedAttr 阅读全文
posted @ 2021-03-31 14:14 该显示昵称已被使用了 阅读(87) 评论(0) 推荐(0)
摘要:源码学习 class SetterAwareType(type): # 元类 def __new__(cls, *args): # print('in SetterAwareType __new__') # print(type(type.__new__(cls, 'hehehe',(object, 阅读全文
posted @ 2021-03-31 09:29 该显示昵称已被使用了 阅读(134) 评论(0) 推荐(0)
摘要:参考资料 https://www.liaoxuefeng.com/wiki/1016959663602400/1017592449371072 https://stackoverflow.com/questions/18513821/python-metaclass-understanding-th 阅读全文
posted @ 2021-03-31 09:28 该显示昵称已被使用了 阅读(102) 评论(0) 推荐(0)
摘要:元类的应用场景 ORM https://www.liaoxuefeng.com/wiki/1016959663602400/1017592449371072 u = User(id=12345, name='Michael', email='test@orm.org', password='my-p 阅读全文
posted @ 2021-03-31 09:27 该显示昵称已被使用了 阅读(84) 评论(0) 推荐(0)
摘要:https://zhuanlan.zhihu.com/p/44667584 #1 闭包+装饰器 def cache(func): amizedata = {} # 闭包,这个值一直在 def wrapper(*args, **kwargs): key = f'{func.__name__}-{str 阅读全文
posted @ 2021-03-29 16:16 该显示昵称已被使用了 阅读(35) 评论(0) 推荐(0)
摘要:https://www.runoob.com/w3cnote/python-yield-used-analysis.html 演进 yield 的作用就是把一个函数变成一个 generator,带有 yield 的函数不再是一个普通函数,Python 解释器会将其视为一个 generator,调用 阅读全文
posted @ 2021-03-26 15:30 该显示昵称已被使用了 阅读(116) 评论(0) 推荐(1)