10
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

bytes→str→dict

Last updated at Posted at 2017-11-23

python3 で b"" になってるやつ
astは標準なのでimport文書くだけ

文字列型

text = bytes.decode('utf-8')

print(text)
print(type(text))

出力

"{'x':1,'y':2}"
<class 'str'>

バイト型

text_bytes = text.encode('utf-8')

print(text_bytes)
print(type(text_bytes))

出力

b"{'x':1,'y':2}"
<class 'bytes'>

辞書型

import ast

text_dic = ast.literal_eval(text)
print(text_dic)
print(type(text_dic))

出力

{'x': 1, 'y': 2}
<class 'dict'>

これで触れる。

10
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?