推荐学习书目
› 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 · May 1, 2018 · 3308 views
    This topic created in 3077 days ago, the information mentioned may be changed or developed.

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

    5 replies  •  2018-05-09 00:40:01 +08:00
    qile1
        1
    qile1  
       May 1, 2018 via Android
    优雅不知道,我都是 str.replac (“ ”,“”).replac (“\r “,””)加一堆
    sjmcefc2
        2
    sjmcefc2  
    OP
       May 1, 2018
    @qile1 刚开始学 python,不知道怎么写的简洁,用上最多的轮子。。。
    Yycreater
        3
    Yycreater  
       May 7, 2018
    cursor.rowcount()这个,查看受影响的行数
    sjmcefc2
        4
    sjmcefc2  
    OP
       May 7, 2018
    @Yycreater 太棒了。谢谢。
    sjmcefc2
        5
    sjmcefc2  
    OP
       May 9, 2018
    @Yycreater 貌似这个没有办法看到错误的信息。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2432 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:16 · PVG 20:16 · LAX 05:16 · JFK 08:16
    ♥ Do have faith in what you're doing.