推荐学习书目
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
eloah
V2EX  ›  Python

Django 和 Python 关于变量名末尾的下划线的冲突

  •  
  •   eloah · Oct 10, 2017 · 2666 views
    This topic created in 3162 days ago, the information mentioned may be changed or developed.

    在 Python 中,有些变量名已经存在内置的方法了,比如id, type等. Python 推荐的做法是在后面加一个下划线,比如id_, type_这样来避免覆盖内置方法.然而 Django 的 ORM 中会强制检查,禁止字段名末尾使用下划线......

    这样的话,应该如何解决好一点呢......

    3 replies    2017-10-10 15:08:01 +08:00
    privil
        1
    privil  
       Oct 10, 2017
    后面再加一个字母……
    awanabe
        2
    awanabe  
       Oct 10, 2017
    xx_id
    xx_type
    eloah
        3
    eloah  
    OP
       Oct 10, 2017
    @awanabe
    然后这样在 orm 中操作就变成了 xxx.xxx_id, xxx.xxx_type 这样了......
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3066 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 14:23 · PVG 22:23 · LAX 07:23 · JFK 10:23
    ♥ Do have faith in what you're doing.