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

请教 Python 下数据库操作 cur.execute()如何获取是否执行成功得信息?如何去掉行尾得换行符号呢?

  •  
  •   sjmcefc2 · 2018-05-01 03:34:13 +08:00 · 2390 次点击
    这是一个创建于 2181 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如 cur.execute(copy talbe from test.txt)?这个怎么知道 copy 了多少 line 呢? 另外就是想按照分节符把一行拆开,然后 insert 到数据库,如何优雅得去掉行尾得换行符? strip ?貌似有帖子说如果是中文,会有 bug 存在。 大神赐教哈,感觉没法把 python 写的简练。

    5 条回复    2018-05-09 00:40:01 +08:00
    qile1
        1
    qile1  
       2018-05-01 15:13:46 +08:00 via Android
    优雅不知道,我都是 str.replac (“ ”,“”).replac (“\r “,””)加一堆
    sjmcefc2
        2
    sjmcefc2  
    OP
       2018-05-01 20:35:23 +08:00
    @qile1 刚开始学 python,不知道怎么写的简洁,用上最多的轮子。。。
    Yycreater
        3
    Yycreater  
       2018-05-07 19:42:08 +08:00
    cursor.rowcount()这个,查看受影响的行数
    sjmcefc2
        4
    sjmcefc2  
    OP
       2018-05-07 22:02:06 +08:00
    @Yycreater 太棒了。谢谢。
    sjmcefc2
        5
    sjmcefc2  
    OP
       2018-05-09 00:40:01 +08:00
    @Yycreater 貌似这个没有办法看到错误的信息。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2243 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:40 · PVG 08:40 · LAX 17:40 · JFK 20:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.