Won‘t implicitly convert Unicode to bytes; use .encode()

在用python写lmdb文件时出现了报错信息"Won't implicitly convert Unicode to bytes; use .encode()

原报错代码:

def writeCache(env, cache):
    with env.begin(write=True) as txn:
        for k, v in cache.items():
            txn.put(k, v)

修改后的代码:

def writeCache(env, cache):
    with env.begin(write=True) as txn:
        for k, v in cache.items():
            txn.put(str(k).encode(), str(v).encode())

posted @ 2022-11-13 22:36  dlhl  阅读(84)  评论(0)    收藏  举报