<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    海上月明

    editer by sun
    posts - 162, comments - 51, trackbacks - 0, articles - 8
       :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

    python操作sqlite3 碰到中文問題

    Posted on 2013-06-07 19:01 pts 閱讀(5843) 評論(0)  編輯  收藏 所屬分類: Python

    錯問癥狀:

    OperationalError: Could not decode to UTF-8 column 'shouji_lanshouyuan' with text '國際2部 鄔長春'

    解決方案:

    conn = sqlite3.connection(" ... ")
    conn.text_factory = str

    解決問題方案來源:http://bbs.csdn.net/topics/250055755

    設置python使用什么類型來處理sqlite3的text類型,默認是unicode,所以才會產生
    OperationalError: Could not decode to UTF-8 column 'name' with text '國內其他' 
    這個錯誤

    因為從數據庫中取出數據時,是gbk編碼(因為你上次存進去的是gbk)
    conn.text_factory的默認值是unicode,python會嘗試將text類型的字段轉換成unicode,就產生了錯誤

     

    附:sqlite3的row操作:

    Row對象的詳細介紹

    class sqlite3.Row

    Row instance serves as a highly optimized row_factory for Connection objects. It tries to mimic a tuple in most of its features.

    It supports mapping access by column name and index, iteration, representation, equality testing and len().

    If two Row objects have exactly the same columns and their members are equal, they compare equal.

    Changed in version 2.6: Added iteration and equality (hashability).

    keys()

    This method returns a tuple of column names. Immediately after a query, it is the first member of each tuple in Cursor.description.

    New in version 2.6.

        下面舉例說明

    復制代碼
    cx.row_factory = sqlite3.Row

    = cx.cursor()

    c.execute('select * from catalog')
     <sqlite3.Cursor object at 0x05666680>

    = c.fetchone()

    type(r)
    <type 'sqlite3.Row'>

    r
    <sqlite3.Row object at 0x05348980>

    print r
    (0, 
    10, u'\u9c7c', u'Yu')

    len(r)
    4

    r[2]            #使用索引查詢
    u'\u9c7c'

    r.keys()
    ['id''pid''name''nickname']

     使用列的關鍵詞查詢
    In [43]: r['id']
    Out[43]: 0
    In [44]: r['name']
    Out[44]: u'\u9c7c'

     

    主站蜘蛛池模板: 免费一级一片一毛片| 国产真人无码作爱视频免费| h视频在线观看免费完整版| 亚洲AV无码一区二区三区DV| 24小时免费直播在线观看| 日日操夜夜操免费视频| 亚洲男人天堂2022| 最新欧洲大片免费在线 | 在人线av无码免费高潮喷水| 伊人久久综在合线亚洲2019| 久久久久高潮毛片免费全部播放 | 亚洲精品在线网站| 1024免费福利永久观看网站| 亚洲人成777在线播放| 妞干网免费观看视频| 亚洲aⅴ无码专区在线观看春色| 日韩中文字幕在线免费观看| 免费看又黄又爽又猛的视频软件 | 久久久久久久亚洲Av无码| 亚洲免费视频网址| 亚洲乱妇老熟女爽到高潮的片| 四色在线精品免费观看| 成人精品综合免费视频| 久久精品国产亚洲综合色| 一级特黄aa毛片免费观看| 亚洲sss综合天堂久久久| 国产公开免费人成视频| 一个人看的www视频免费在线观看| 国产成人精品日本亚洲专区61| 午夜精品免费在线观看 | 免费一级毛片在线播放放视频| 区久久AAA片69亚洲| 在线a免费观看最新网站| 亚洲一区二区观看播放| 亚洲免费在线观看| 亚洲人av高清无码| 国产亚洲AV手机在线观看| 69成人免费视频| 一级毛片免费播放男男| 亚洲欧洲尹人香蕉综合| 四虎国产精品免费久久影院|