maga
V2EX  ›  问与答

有办法让 python mysqldb 取出是 unicode 编码而不是 utf8 吗

  •  
  •   maga · Jun 15, 2014 · 3232 views
    This topic created in 4377 days ago, the information mentioned may be changed or developed.
    我用mysqldb 存入与取出都是utf8编码。 但python内部是unicode的,所以每次我都还要将从数据库取出的数据转换成unicode, 很是麻烦与低效, 有什么办法让mysqldb取出的就是unicode编码的吗?


    def _dict_to_unicode(self, d):
    d = json.dumps(d, ensure_ascii = False)
    d = json.loads(d)
    return d
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3192 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 11:29 · PVG 19:29 · LAX 04:29 · JFK 07:29
    ♥ Do have faith in what you're doing.