随笔分类 -  python

摘要:编码 Python的世界中内存中统一使用Unicode,使用时转换为其他编码,比如网页/文档编辑器 Python3中字符串类型 str 使用Unicode编码,而I/O得到的是字节码 byte,使用内建函数可以相互转换 (python中encode后得到的bytes如果不能用ascii呈现,比如中文 阅读全文
posted @ 2017-05-30 13:00 autoria 阅读(331) 评论(0) 推荐(0)
摘要:Python functool Python中的装饰器 Python decorator module document 使用functool中的wraps,可以复制一些信息(__name__, __doc__, __module__, __dict__),但是signature还是会被改变(比如参 阅读全文
posted @ 2017-05-13 11:25 autoria 阅读(496) 评论(0) 推荐(0)
摘要:Specification Summary 除了作为一个statement将一个函数变成一个generator以外,yield可以被视为是一个表达式,并用于赋值。 比如 可以看到我们在访问迭代器之前需要首先对迭代器get_primes的实例使用send,传入None,为什么呢?因为: 阅读全文
posted @ 2017-04-04 23:41 autoria 阅读(222) 评论(0) 推荐(0)
摘要:This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. The returned 阅读全文
posted @ 2016-12-10 20:24 autoria 阅读(274) 评论(0) 推荐(0)
摘要:虽然可以通过元组实现相关的功能,但是因为实际中的使用需求,最终实现了装饰器。 刚开始python仅仅支持@staticmethod一类的装饰器,后来才觉得应该广泛地支持decorator,@这个符号一开始参考自java annotation,Barry Warsaw 称之为pie-decorator 阅读全文
posted @ 2016-12-10 20:23 autoria 阅读(297) 评论(0) 推荐(0)
摘要:类也是对象,但是类有创建对象的能力 动态创建一个类: type的语法:type(类名, 父类的元组(针对继承的情况,可以为空),包含属性的字典(名称和值)) type的语法:type(类名, 父类的元组(针对继承的情况,可以为空),包含属性的字典(名称和值)) 创建类的就是元类,type是所有类的元 阅读全文
posted @ 2016-12-10 13:31 autoria 阅读(816) 评论(0) 推荐(0)
摘要:iterator支持两种builtin types:__iter__ 和 __next__,资料:https://docs.python.org/2/library/stdtypes.html#iterator.next generator:https://wiki.python.org/moin/ 阅读全文
posted @ 2016-11-08 00:11 autoria 阅读(166) 评论(0) 推荐(0)