python
文章平均质量分 89
hulpmi
这个作者很懒,什么都没留下…
展开
-
python decorator
Q1. what is decorator in pythonQ2. how do decorated functions work in flask/python? (app.route)引申: Metaprogramming is a programming technique in which computer programs have the ability to treat pr...原创 2018-06-29 17:01:09 · 140 阅读 · 0 评论 -
python's __new__ magic method and using in singleton pattern
------why I want to know python's magic method named __new__ , and what it will do in singleton pattern,because I found them in my company's job interview questions, but I don't know how to answe...转载 2019-03-12 10:39:01 · 131 阅读 · 0 评论 -
__getattribute__方法
流畅的python19.6节 处理属性的特殊方法 在用户自己定义的类中,下述特殊方法用于获取、设置、删除和列出属性。使用点号或内置的 getattr、hasattr 和 setattr 函数存取属性都会触发下述列表中相应的特殊方法。但是,直接通过实例的 __dict__ 属性读写属性不会触发这些特殊方法——如果需要,通常会使用这种方式跳过特殊方法。Python 文档“D...转载 2019-03-12 10:06:49 · 3391 阅读 · 0 评论 -
时间计数器
timeit.Timer( '[item for sublist in l for item in sublist]', 'l=[[1, 2, 3], [4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7]] * 10' ).timeit()原创 2019-03-15 15:21:12 · 1151 阅读 · 0 评论 -
graphQL--what's mutations,Update data with mutations
TheMutationcomponent is another important building block in an Apollo app. It’s a React component that provides a function to execute a GraphQL mutation. Additionally, it tracks the loading, complet...原创 2019-03-15 14:40:56 · 181 阅读 · 0 评论 -
sqlalchemy orm case用法
See sqlalchemy.sql.expression.case function and more examples on the documentation page. But it would look like this (verbatim from the documentation linked to):case([(orderline.c.qty > 100, ite...转载 2019-02-18 14:07:27 · 3166 阅读 · 0 评论 -
sqlalchemy hybrid attribute
The hybrid takes advantage of the ability of Python classes to have an attribute which has customizable behavior both at the class level as well as at the instance level原创 2018-12-03 10:12:01 · 165 阅读 · 0 评论 -
将sqlalchemy result对象转换为dict对象
# method1for r in session.query(User).all(): row2dict = lambda r: {c.name: str(getattr(r, c.name)) for c in r.__table__.columns} print(row2dict(r))# method2def row2dict(row): d = {}...原创 2019-03-12 14:24:50 · 4203 阅读 · 1 评论