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

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

  •  
  •   omg21 · 2016-06-20 20:05:56 +08:00 · 1847 次点击
    这是一个创建于 2891 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2016-06-20 21:13:39 +08:00
    Kilerd
        1
    Kilerd  
       2016-06-20 21:13:39 +08:00
    你需要一个 ORM
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4981 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:59 · PVG 14:59 · LAX 23:59 · JFK 02:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.