[Python] Come scrivere un array di bytes in un file binario
Patrizio.Ferlito a b-source.ch
Patrizio.Ferlito a b-source.ch
Lun 1 Ott 2007 15:51:30 CEST
soluzione trovata:
file = open(fileName, 'wb')
for entry in bytes:
file.write(struct.pack('b', entry))
file.close()
e verifica del file prodotto:
jar tvf /products/.../DummyEvent-sbconfig.jar
23728 Mon Oct 01 15:49:26 CEST 2007 ExportInfo
264 Mon Oct 01 15:49:26 CEST 2007 EventBus-DummyEvent/providers/Provider2/_folderdata.LocationData
11553 Mon Oct 01 15:49:26 CEST 2007 EventBus-DummyEvent/providers/Provider2/DummyEvent-Provider2-SingleXMLFileProvid.ProxyService
686 Mon Oct 01 15:49:26 CEST 2007 EventBus-DummyEvent/consumers/Consumer1/resource/DummyEvent-Consumer1-ConsumerEventTransf.Xquery
...
ciao
ferp
-----Original Message-----
From: python-bounces a lists.python.it [mailto:python-bounces a lists.python.it] On Behalf Of Francesco Guerrieri
Sent: luned́, 1. ottobre 2007 15:31
To: Discussioni generali sul linguaggio Python
Subject: Re: [Python] Come scrivere un array di bytes in un file binario
On 10/1/07, Patrizio.Ferlito a b-source.ch <Patrizio.Ferlito a b-source.ch> wrote:
> provato ma:
>
> cat my.jar
> array([80, 75, 3, 4, 20, 0, 8, 0, 8, 0, -111, 121, 65, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, ...., 0, 0, 0], byte)
Questo vuol dire che str(bytes) ha quella rappresentazione. Cosa ti
aspettavi invece?
Potresti provare a usare
output_file.write(repr(bytes))
ciao
francesco
_______________________________________________
Python mailing list
Python a lists.python.it
http://lists.python.it/mailman/listinfo/python
IMPORTANT:
This e-mail transmission is intended for the named
addressee(s)only.
Its contents are private, confidential and protected
from disclosure and should not be read, copied or
disclosed by any other person.
If you are not the intended recipient, we kindly ask
you to notify the sender immediately by telephone
(+41 (0)58 806 50 00), to redirect the message to the
account "info a b-source.ch" and to delete this e-mail.
E-mail transmissions may be intercepted, altered or
read by unauthorized persons and may contain viruses.
Therefore, it is recommended that you use regular mail
or courier services for any information intended to be
confidential. However, by sending us messages through
e-mail, you authorize and instruct us to correspond by
e-mail in the relevant matter.
Thank you.
Maggiori informazioni sulla lista
Python