Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のようなpythonリストがあります。
list = [u'a', u'b', u'c']
今、UTF-8でエンコードしたいと思います。したがって、私は使用する必要があります:
list = list[0].encode("utf-8")
しかし、印刷リストは
a
リストの最初の要素を意味します。もうリストすらありません。私は何を間違っていますか?
>>> items = [u'a', u'b', u'c'] >>> [x.encode('utf-8') for x in items] ['a', 'b', 'c']
list[0]リストではなく、最初の要素です。listvar を新しい値、つまり最初の要素の utf-8 エンコーディングに再割り当てしています。
list[0]
list
listまた、関数をマスクするため、変数に名前を付けないでくださいlist()。
list()