pythonのメモ
pythonを使った時のテストコード。
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'])
0 件のコメント:
コメントを投稿
次の投稿
前の投稿
ホーム
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿