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

请教 Python 操作 Sqlite3 数据库和 Webpy 关于日期编码的问题

  •  
  •   Sargas · Nov 12, 2015 · 3734 views
    This topic created in 3969 days ago, the information mentioned may be changed or developed.
    本人自学 Python 不久。今天学习用 Python 操作 Sqlite3 数据库时遇到一个问题,向大家请教一下。
    Windows 环境下, UTF8 编码的数据库,其中的日期字段,在数据库内是 datetext 类型。直接写 Python 查询,返回显示“ 2015 年 11 月 12 日 星期四”;同样的代码,输出到 webpy 之后,在网页中显示的是 u'2015\u5e7412\u670831\u65e5 \u661f\u671f\u56db'这种。在数据库连接中设置 con.text_factory = str 之后, web 输出变成'2015\xe5\xb9\xb412\xe6\x9c\x8824\xe6\x97\xa5 \xe6\x98\x9f\xe6\x9c\x9f\xe5\x9b\x9b',这种。
    我应该怎么处理才能让代码在 web 页面中也是显示成“ 2015 年 11 月 12 日 星期四”?
    3 replies  •  2015-11-13 00:34:15 +08:00
    goodryb
        1
    goodryb  
       Nov 12, 2015
    >>> a=u'2015\u5e7412\u670831\u65e5 \u661f\u671f\u56db'
    >>> print a.encode('gbk')
    2015 年 12 月 31 日 星期四
    Sargas
        2
    Sargas  
    OP
       Nov 12, 2015
    @goodryb 谢谢!这个办法我知道,先按这个办法来吧。
    liujianpc
        3
    liujianpc  
       Nov 13, 2015 via iPhone
    Python 的编码问题和版本问题,真的很蛋疼
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   836 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 20:43 · PVG 04:43 · LAX 13:43 · JFK 16:43
    ♥ Do have faith in what you're doing.