推荐学习书目
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 · Apr 13, 2023 · 2009 views
    This topic created in 1149 days ago, the information mentioned may be changed or developed.
    
    from sqlalchemy import select
    stmt = select(User).where(User.name == "spongebob")
    
    

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

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

    6 replies    2023-04-15 02:30:01 +08:00
    think2011
        1
    think2011  
    OP
       Apr 13, 2023
    没有人知道吗?😥
    beeeeeeat
        2
    beeeeeeat  
       Apr 13, 2023 via iPhone
    Field.__eq__
    Alias4ck
        3
    Alias4ck  
       Apr 14, 2023   ❤️ 1
    chaoshui
        4
    chaoshui  
       Apr 14, 2023
    大概率是运算符重载
    Pzqqt
        5
    Pzqqt  
       Apr 14, 2023   ❤️ 1
    think2011
        6
    think2011  
    OP
       Apr 15, 2023
    原来如此 谢谢各位大佬!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1304 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 23:49 · PVG 07:49 · LAX 16:49 · JFK 19:49
    ♥ Do have faith in what you're doing.