database = mongo_connect()
un = str(session['username'])
database.game.insert({'host': session['username'],
'player_list':[un]})
如果我这样做,那么当我检索player_list时,我会得到一个unicodes列表。我怎样才能得到一个字符串列表?感谢
答案 0 :(得分:1)
因为mongodb stores data in bson format, and since bson is utf8-encoded, you'll get only unicode strings。
无论如何,您可以将unicode
编码为str
;
player_list = [x.encode('utf-8') for x in player_list]