Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasar dic a bytes #381

Open
7 tasks
Couyoumdjian13 opened this issue Nov 11, 2022 · 1 comment
Open
7 tasks

Pasar dic a bytes #381

Couyoumdjian13 opened this issue Nov 11, 2022 · 1 comment
Assignees
Labels

Comments

@Couyoumdjian13
Copy link

Prerrequisitos

(Marcar colocando una X entre los corchetes los ítems que ya hiciste, así: "[X]")

Duda

Holaa, intento pasar el diccionario a bytes con:
dict_j = json.dumps(test_dict)
bytes_dic = dict_j.encode()
pero al printear "bytes_dic", me printea un diccionario pero tipo bytes.
quiero saber como hacer para que me quede en formato "b'\x00\x00\x00\x13'" por ejemplo, para luego hacer un bytearray

@Hernan4444
Copy link
Contributor

Hola,

Con lo que haces ya es suficiente para tener todo en bytes, cuando haces print, python te mostrará el bytes de la mejor forma que él estima convenitente y no necesariamente será en hexadecimal como en "b'\x00\x00\x00\x13'". Pero si haces bytes_dic[0] te retonará un número que corresponderá al primer bytes, bytes_dic[1] será el segundo bytes y así sucesivaente.

Esto tambien pasa con el b'\x09' que python lo mostrará como b'\t' pero es lo mismo, solo es la forma visual que python hace para mostrar el bytes.

Saludosヾ(^-^)ノ

@Hernan4444 Hernan4444 self-assigned this Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants