推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
casparchen
V2EX  ›  Python

Python 中以逻辑表达式为参数的函数的实现方式

  •  
  •   casparchen · Jan 14, 2019 · 1994 views
    This topic created in 2825 days ago, the information mentioned may be changed or developed.

    比如大多数的 ORM 都支持如下的用法

    Person.select().where(Person.name == 'Dave').get()
    

    , 像这个 where 有什么简洁的实现方式吗?(除了重载 Person.name 的 __eq__ 外)。

    另外这个一般是怎么实现的? 谢谢。

    2 replies  •  2019-01-15 10:11:23 +08:00
    cyspy
        1
    cyspy  
       Jan 14, 2019
    看了下 Spark 的实现,是把字段抽象成 Column,再重载 __eq__ ,就只需要写一次了
    xpresslink
        2
    xpresslink  
       Jan 15, 2019
    楼主研究下 ORM 的源码吧。
    推荐去看一下 Django 内置的 ORM,比较直接好理解,我阅读过大部分。
    或者 peewee 那个就一个文件把 ORM 最基本的东西都实现了。
    实在是行有余力可以学 sqlalchemy。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3604 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 04:25 · PVG 12:25 · LAX 21:25 · JFK 00:25
    ♥ Do have faith in what you're doing.