Ciao, perche' di default viene rispettato l'allineamento che il dato dovrebbe avere in memoria se fosse una struttura c:
https://docs.python.org/3/library/struct.html#struct-alignment Roberto De Ioris Il giorno gio 21 ott 2021 alle ore 11:12 Marco De Paoli <depao...@gmail.com> ha scritto: > ciao a tutti! > ho un problema con struct.unpack e non capisco cosa sto sbagliando... > > >>> struct.unpack("i", b'\x03\x00\x00\x00') # OK! > (3,) > >>> struct.unpack("ih", b'\x03\x00\x00\x00\x04\x00') # OK! > (3, 4) > >>> struct.unpack("ihi", b'\x03\x00\x00\x00\x04\x00\x00\x00\x04\x00') # > ARGHHH > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > struct.error: unpack requires a buffer of 12 bytes > > Perché mai se ne aspetta 12? Dovrebbero bastare i 10 che ci sono nel > buffer! > > Mi aspettavo: > >>> struct.unpack("ihi", b'\x03\x00\x00\x00\x04\x00\x00\x00\x04\x00') > (3, 4, 4) > > Cosa sto sbagliando? > > Marco > _______________________________________________ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python >
_______________________________________________ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python