请教 Python 操作 Sqlite3 数据库和 Webpy 关于日期编码的问题 - 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
Sargas

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

  •  
  •   Sargas Nov 12, 2015 3453 views
    This topic created in 3834 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     Solana     5812 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 43ms UTC 02:41 PVG 10:41 LAX 19:41 JFK 22:41
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86