<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'

     

    主站蜘蛛池模板: 九九久久国产精品免费热6| 国产午夜亚洲精品理论片不卡 | 亚洲精品第一国产综合精品| 亚洲精品无码午夜福利中文字幕| 怡红院亚洲怡红院首页| 亚洲精品国产福利一二区| 亚洲高清最新av网站| 亚洲欧洲中文日韩av乱码| 久久久久亚洲AV成人网人人网站| 免费一级e一片在线播放| 四虎精品亚洲一区二区三区| 免费观看国产小粉嫩喷水| yy6080久久亚洲精品| 亚洲中文字幕视频国产| 国产美女亚洲精品久久久综合| 国产精品亚洲玖玖玖在线观看| 久久精品国产亚洲Aⅴ香蕉| 亚洲女初尝黑人巨高清| 亚洲国产无套无码av电影| 五月天网站亚洲小说| 亚洲成av人片不卡无码| 亚洲影院天堂中文av色| 国产亚洲福利一区二区免费看 | 亚洲一级大黄大色毛片| 亚洲偷偷自拍高清| 国产亚洲美女精品久久久久| 九九免费精品视频在这里| 色www永久免费网站| 91嫩草免费国产永久入口| 波多野结衣久久高清免费| 亚洲精品成人久久久| 国产av天堂亚洲国产av天堂| 亚洲精品国产第1页| 337p日本欧洲亚洲大胆人人 | 亚洲国产美女福利直播秀一区二区| 亚洲国产成人九九综合| 在线视频亚洲一区| 中文在线日本免费永久18近| 91精品手机国产免费| 国产男女猛烈无遮档免费视频网站| 中文字幕无码精品亚洲资源网|