V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2019-01-14 23:12:18 +08:00 · 1317 次点击
    这是一个创建于 1928 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

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

    2 条回复    2019-01-15 10:11:23 +08:00
    cyspy
        1
    cyspy  
       2019-01-14 23:22:16 +08:00
    看了下 Spark 的实现,是把字段抽象成 Column,再重载 __eq__ ,就只需要写一次了
    xpresslink
        2
    xpresslink  
       2019-01-15 10:11:23 +08:00
    楼主研究下 ORM 的源码吧。
    推荐去看一下 Django 内置的 ORM,比较直接好理解,我阅读过大部分。
    或者 peewee 那个就一个文件把 ORM 最基本的东西都实现了。
    实在是行有余力可以学 sqlalchemy。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1006 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:37 · PVG 03:37 · LAX 12:37 · JFK 15:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.