pythonのメモ
pythonを使った時のテストコード。
ラベル
ast
の投稿を表示しています。
すべての投稿を表示
ラベル
ast
の投稿を表示しています。
すべての投稿を表示
2017/10/23
文字列を辞書型に変換
文字列になっている辞書型想定文字を辞書型に変換する。
dictでキャストしようとすると「dictionary update sequence element #0 has length 1; 1 is required」と出る。
astモジュールを使用で解決した。
Anaconda 3, python 3.6 64bit
Windows 10 64bit
import ast s = "{'ID':'komugi','state':'pan'}" print(type(s)) print(s) d = ast.literal_eval(s) print(type(d)) print(d) print(d['ID'])
前の投稿
ホーム
登録:
コメント (Atom)