Re: [Python3] Reading a binary file and wrtiting the bytes verbatim?in an utf-8 file

2010-04-25 Thread fab
Another possibility is to open the file in binary mode and do the encoding yourself when writing text. This might actually be a better solution, since I'm not sure RTF uses utf-8 by default. Yes, thanks for this suggestion, it seems the best to me. Actually RTF is not UTF-8 encoded, it's

Re: [Python3] Reading a binary file and wrtiting the bytes verbatim in an utf-8 file

2010-04-24 Thread Antoine Pitrou
Hello, I have to read the contents of a binary file (a PNG file exactly), and dump it into an RTF file. The RTF-file has been opened with codecs.open in utf-8 mode. You should use the built-in open() function. codecs.open() is outdated in Python 3. As I expected, the utf-8 decoder

Re: [Python3] Reading a binary file and wrtiting the bytes verbatim in an utf-8 file

2010-04-24 Thread Stefan Behnel
Antoine Pitrou, 25.04.2010 02:16: Another possibility is to open the file in binary mode and do the encoding yourself when writing text. This might actually be a better solution, since I'm not sure RTF uses utf-8 by default. That's a lot cleaner as it doesn't use two interfaces to write to the

[Python3] Reading a binary file and wrtiting the bytes verbatim in an utf-8 file

2010-04-23 Thread fab
Hello. I have to read the contents of a binary file (a PNG file exactly), and dump it into an RTF file. The RTF-file has been opened with codecs.open in utf-8 mode. As I expected, the utf-8 decoder chokes on some combinations of bits; how can I tell python to dump the bytes as they are, without

Re: [Python3] Reading a binary file and wrtiting the bytes verbatim in an utf-8 file

2010-04-23 Thread Chris Rebert
On Fri, Apr 23, 2010 at 9:22 AM, f...@slick.airforce-one.org wrote: I have to read the contents of a binary file (a PNG file exactly), and dump it into an RTF file. The RTF-file has been opened with codecs.open in utf-8 mode. As I expected, the utf-8 decoder You mean encoder. chokes on

Re: [Python3] Reading a binary file and wrtiting the bytes verbatim in an utf-8 file

2010-04-23 Thread Chris Rebert
On Fri, Apr 23, 2010 at 9:48 AM, Chris Rebert c...@rebertia.com wrote: On Fri, Apr 23, 2010 at 9:22 AM,  f...@slick.airforce-one.org wrote: I have to read the contents of a binary file (a PNG file exactly), and dump it into an RTF file. snip how can I tell python to dump the bytes as they are,

Re: [Python3] Reading a binary file and wrtiting the bytes verbatim ?in an utf-8 file

2010-04-23 Thread fab
Thanks, I'll try this. I have no idea how you'd go about reading the contents of such a file in a sensible way. The purpose is to embed PNG pictures in an RTF file that will be read by OpenOffice. It seems that OpenOffice reads RTF in 8-bit, so it should be ok. The RTF is produced from a TeX