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
think2011
V2EX  ›  Python

很好奇 sqlalchemy 的 where(User.name == "spongebob") 是怎么实现传入的是表达式,而不是计算后的布尔值

  •  
  •   think2011 ·
    think2011 · 2023-04-13 02:30:10 +08:00 · 886 次点击
    这是一个创建于 373 天前的主题,其中的信息可能已经有所发展或是发生改变。
    
    from sqlalchemy import select
    stmt = select(User).where(User.name == "spongebob")
    
    

    例如以上代码中 User.name == "spongebob" 会被解释成表达式参数,而不是我理解的变成一个布尔值(True or False)参数

    是怎么做到的,这是 python 本身支持的语法吗? 总觉得很误导,像是 bug 一样

    6 条回复    2023-04-15 02:30:01 +08:00
    think2011
        1
    think2011  
    OP
       2023-04-13 15:20:59 +08:00
    没有人知道吗?😥
    beeeeeeat
        2
    beeeeeeat  
       2023-04-13 20:13:45 +08:00 via iPhone
    Field.__eq__
    Alias4ck
        3
    Alias4ck  
       2023-04-14 11:29:43 +08:00   ❤️ 1
    chaoshui
        4
    chaoshui  
       2023-04-14 11:34:01 +08:00
    大概率是运算符重载
    Pzqqt
        5
    Pzqqt  
       2023-04-14 12:47:54 +08:00   ❤️ 1
    think2011
        6
    think2011  
    OP
       2023-04-15 02:30:01 +08:00
    原来如此 谢谢各位大佬!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1017 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:09 · PVG 03:09 · LAX 12:09 · JFK 15:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.