Answers for "write dict as bytes python"

0

dict to bytes python

# 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}'
Posted by: Guest on July-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language