随笔分类 -  Python基础

摘要:传送门 1. https://docs.python.org/3/reference/datamodel.html object.\_\_getattr_\_ 2. https://docs.python.org/3/reference/datamodel.html object.\_\_getat 阅读全文
posted @ 2018-07-19 10:14 Rocin 阅读(199) 评论(0) 推荐(0)
摘要:\__x会自动变形为\_类名\__x 正常情况 把foo定义成私有 原理:父类的__x私有属性在定义时已经变形为_父类__x,子类可以继承这个属性,但无法覆盖。所以test()里面的self.__foo的self已经绑定了父类,子类的__foo()无法覆盖。 Python的私有属性的缺点 这种变形并 阅读全文
posted @ 2018-07-11 23:36 Rocin 阅读(231) 评论(0) 推荐(0)
摘要:传送门 https://blog.csdn.net/jackfrued/article/details/79717727 在此基础上实践和改编某些点 1. 并发编程 1. 实现让程序同时执行多个任务也就是常说的“并发编程” 2. 使用Python实现并发编程主要有3种方式:多进程、多线程、多进程+多 阅读全文
posted @ 2018-06-25 23:06 Rocin 阅读(356) 评论(0) 推荐(0)
摘要:传送门 1. https://github.com/jackfrued/Python 100 Days/blob/master/Day01 15/Day09/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E8%BF%9B%E9%98%B6.md %E9%9D%99%E6% 阅读全文
posted @ 2018-06-23 22:10 Rocin 阅读(296) 评论(0) 推荐(0)
摘要:参考 1. https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143186739713011a09b63dcbd42cc87f907a778b3ac73000 概念 限制实例的属 阅读全文
posted @ 2018-06-23 21:50 Rocin 阅读(132) 评论(0) 推荐(0)
摘要:参考 https://stackoverflow.com/questions/36834677/print success messages for asserts in python 总结 在assert后加上print 阅读全文
posted @ 2018-06-22 20:25 Rocin 阅读(683) 评论(0) 推荐(0)
摘要:说明 代码片段来自网上搬运的或者自己写的 华氏温度转摄氏温度 输入圆的半径计算计算周长和面积 输入年份判断是不是闰年 英制单位与公制单位互换 掷骰子决定做什么 百分制成绩转等级制 输入三条边长如果能构成三角形就计算周长和面积 上面的代码中使用了math模块的sqrt函数来计算平方根。用边长计算三角形 阅读全文
posted @ 2018-06-16 16:40 Rocin 阅读(451) 评论(0) 推荐(0)
摘要:1.1 如果导入的模块除了定义函数之外还中有可以执行代码,那么Python解释器在导入这个模块时就会执行这些代码。 module1.py: test.py: 1.2 模块编写的目的是被调用;一般来说,不是主程序入口;假如直接运行该模块,使用if \__name__ == '\__main__': m 阅读全文
posted @ 2018-06-13 15:44 Rocin 阅读(171) 评论(0) 推荐(0)
摘要:传送门 1. https://stackoverflow.com/a/20980488/5955399 区别 1. json:用于字符串(unicode text)和python基本数据类型间进行转换。优点:跨语言跨平台,应用范围大,体积小;缺点:只能支持 int/str/list/tuple/di 阅读全文
posted @ 2018-06-11 18:25 Rocin 阅读(145) 评论(0) 推荐(0)
摘要:参考,搬运 1. http://python web guide.readthedocs.io/zh/latest/idiom/idiom.html 2. 待定 1. Python支持链式比较 4. 格式化字符时多使用format函数 5. 使用列表或者字典comprehension(推导式) 6. 阅读全文
posted @ 2018-06-05 15:48 Rocin 阅读(362) 评论(0) 推荐(0)
摘要:参考 1. https://stackoverflow.com/questions/2124190/how do i implement interfaces in python 2. https://stackoverflow.com/questions/372042/difference bet 阅读全文
posted @ 2018-05-26 12:35 Rocin 阅读(14295) 评论(0) 推荐(1)
摘要:1. 命名空间和作用域参考 1. https://blog.csdn.net/sakurainluojia/article/details/72783752 2. https://docs.python.org/3.6/tutorial/classes.html 概念 A scope is a te 阅读全文
posted @ 2018-05-22 16:53 Rocin 阅读(226) 评论(0) 推荐(0)
摘要:1. 参数排放顺序:位置参数 args 默认参数 kwargs 2. 动态传参 参数不定个数用 args, kwargs接收: args是元祖形式,接收除去键值对以外的所有参数。 kwargs接收的只是键值对的参数,并保存在字典中。 阅读全文
posted @ 2018-05-22 08:10 Rocin 阅读(217) 评论(0) 推荐(0)
摘要:1. 列表转换成字符串,用''.join() 2. 字符串转换为列表,用split() 阅读全文
posted @ 2018-05-20 09:18 Rocin 阅读(256) 评论(0) 推荐(0)
摘要:1. 概念 1. 目标:类/对象操作 SQL语句 DB API 再在数据库中执行。ORM做前两部,因为ORM本身无法操作数据库。参考:https://baike.baidu.com/item/ORM/3583252?fr=aladdin 2. 本质:类(class Users)对应数据库的表,类中的 阅读全文
posted @ 2018-05-19 12:36 Rocin 阅读(295) 评论(0) 推荐(0)
摘要:参考 1. https://stackoverflow.com/questions/2010692/what does mro do 2. http://python.jobbole.com/85685/ 问题:Python支持多继承,如果父类存在同名函数,该调用哪个? 解决这个问题用MRO(Met 阅读全文
posted @ 2018-05-19 09:46 Rocin 阅读(133) 评论(0) 推荐(0)
摘要:参考 1. https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014319106919344c4ef8b1e04c48778bb45796e0335839000 2. https: 阅读全文
posted @ 2018-05-17 20:55 Rocin 阅读(172) 评论(0) 推荐(0)
摘要:上下文管理协议(Context Management Protocol):包含方法 __enter__() 和 __exit__(),支持该协议的对象要实现这两个方法。 with实现了上下文管理协议,用户有__enter__和__exit__ 阅读全文
posted @ 2018-05-16 21:45 Rocin 阅读(192) 评论(0) 推荐(0)
摘要:1. Web框架数据库相关 1.1 Django django ORM (ORM模块里调用pymysql/MySQLdb模块) 1.2 Flask/其他: 1.2.1 原生SQL pymysql(2/3) MySQLdb(2) 1.2.2 SQLAchemy(ORM) (ORM模块里调用pymysq 阅读全文
posted @ 2018-05-15 15:49 Rocin 阅读(167) 评论(0) 推荐(0)
摘要:``` class Foo(object): def __init__(self): # 1. 用父类object的__setattr__写没有问题,因为是调用object里的__setattr__,所以Foo里的__setattr__不会执行,也就没有递归了 # 2. 这样以后,Foo()对象也有storage变量了,是一个{}。 obj... 阅读全文
posted @ 2018-05-10 14:55 Rocin 阅读(239) 评论(0) 推荐(0)