“Python -Bytes zu diktieren” Code-Antworten

Python -Bytes zu diktieren

# credit to the Stack Overflow user in the source linnk
# Python3

import ast

byte_str = b"{'one': 1, 'two': 2}"
dict_str = byte_str.decode("UTF-8")
my_data = ast.literal_eval(dict_str)

print(repr(my_data))
>>> {'one': 1, 'two': 2}
wolf-like_hunter

Bytes Python diktieren

# You can use indent option in json.dumps() to obtain \n symbols:

	import json

	user_dict = {'name': 'dinesh', 'code': 'dr-01'}
	user_encode_data = json.dumps(user_dict, indent=2).encode('utf-8')
	print(user_encode_data)

# Output:
	b'{\n  "name": "dinesh",\n  "code": "dr-01"\n}'
rng70

Ähnliche Antworten wie “Python -Bytes zu diktieren”

Fragen ähnlich wie “Python -Bytes zu diktieren”

Weitere verwandte Antworten zu “Python -Bytes zu diktieren” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen