V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
omg21
V2EX  ›  Python

pypyodbc 报错: AttributeError: 'Row' object has no attribute 'id'

  •  
  •   omg21 · Jun 20, 2016 · 2233 views
    This topic created in 3609 days ago, the information mentioned may be changed or developed.
    dbstr = "select * from list"
    db.execute(dbstr)
    rows = db.fetchall()
    for row in rows:
    print(row.id)

    用 pypyodbc 连接 Access 数据库,我想取出 list 表中的每条记录的 id ,但是
    运行时报错: AttributeError: 'Row' object has no attribute 'id'
    把 print(row.id)改成 print(row[0])时通过。
    这样其实也能用,但是通用性就差了好多,如果我在 id 字段的前边插入一个新字段,那么相应的程序代码也得从 0 改成 1 ,有什么办法能用 row.id 表示吗?
    1 replies    2016-06-20 21:13:39 +08:00
    Kilerd
        1
    Kilerd  
       Jun 20, 2016
    你需要一个 ORM
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3208 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:56 · PVG 18:56 · LAX 03:56 · JFK 06:56
    ♥ Do have faith in what you're doing.