随笔分类 -  python

摘要:Cpython 2.7 分支中,dict 对象的源代码 lookdict 搜索算法 两个问题无法理解: 1.1 dict 对象搜索算法中,进入【2】处已经说明了 ep->me_key!=key 这个条件成立,但是 【2】那里为啥要再次比较一次 me_key 和 key 呢? 百思不得其解!!! 原因 阅读全文
posted @ 2018-07-29 21:27 木易小邪 阅读(354) 评论(0) 推荐(0)
摘要:https://www.python.org/dev/peps/ KEY 阅读全文
posted @ 2018-06-26 20:21 木易小邪 阅读(239) 评论(0) 推荐(0)
摘要:https://www.python.org/dev/peps/ 阅读全文
posted @ 2018-06-26 19:34 木易小邪 阅读(160) 评论(0) 推荐(0)
摘要:def add_to(num, target=[]): target.append(num) return target print add_to(1) print add_to(2) print add_to(3) 输出非常的怪异,[1],[1,2],[1,2,3],并不是我们想象中的 [1] ,[2],[3] 点解??? 这是列表的可变性在作怪。在Pyth... 阅读全文
posted @ 2018-06-20 16:50 木易小邪 阅读(308) 评论(0) 推荐(0)
摘要:转自 http://www.cnblogs.com/jebeljebel/p/4006433.html 侵删 num = "1" #unicodenum.isdigit() # Truenum.isdecimal() # Truenum.isnumeric() # Truenum = "1" # 全 阅读全文
posted @ 2017-06-09 10:44 木易小邪 阅读(697) 评论(0) 推荐(0)
摘要:7-9. 翻译(a) 编写一个字符翻译程序(功能类似于Unix 中的tr 命令)。我们将这个函数叫做tr(),它有三个字符串做参数: 源字符串、目的字符串、基本字符串,语法定义如下:def tr(srcstr, dststr, string)srcstr 的内容是你打算“翻译”的字符集合,dsrst 阅读全文
posted @ 2017-06-09 10:35 木易小邪 阅读(354) 评论(1) 推荐(0)
摘要:6-6 创建一个类似 string.strip() 函数 方法一 低效方法 大量复制和生成子串对象 def str_strip(s): while len(s)>=2: if s[0]==' ': s=s[1:] else: break while len(s)>=2: if s[-1]==' ': 阅读全文
posted @ 2017-06-04 17:39 木易小邪 阅读(343) 评论(0) 推荐(0)
摘要:Drop-in replacement is a term used in computer science and other fields. It refers to the ability to replace one hardware (or software) component with 阅读全文
posted @ 2017-05-26 16:32 木易小邪 阅读(588) 评论(0) 推荐(0)
摘要:各种有用的三方库总结: https://awesome-python.com/#algorithms-and-design-patterns 阅读全文
posted @ 2017-05-18 17:19 木易小邪 阅读(277) 评论(0) 推荐(0)
摘要:背景 有一些任务,可能事先需要设置,事后做清理工作。对于这种场景,Python的with语句提供了一种非常方便的处理方式。 with如何工作? 紧跟with后面的语句被求值后,返回对象的 __enter__() 方法被调用,这个方法的返回值将被赋值给as后面的变量。 当with后面的代码块全部被执行 阅读全文
posted @ 2017-05-18 15:24 木易小邪 阅读(13649) 评论(0) 推荐(1)
摘要:Mac os x 升级到最新版后出现 python MysqlDB 无法找到 libmysqlclient.18.dylib 的问题,尝试的解决方案如下: 1. 升级更新 mysql 到最新版,无效; 2. 升级 python mysqlDB 到最新版,无效; 3. 将 libmysqlclient 阅读全文
posted @ 2016-07-05 20:28 木易小邪 阅读(1960) 评论(0) 推荐(0)