Python3: Reading a text/binary mixed file

Paulo da Silva p_s_d_a_s_i_l_v_a_ns at netcabo.pt
Tue Mar 10 00:07:16 EDT 2015


On 10-03-2015 00:56, Chris Angelico wrote:
> On Tue, Mar 10, 2015 at 11:45 AM, Paulo da Silva
> <p_s_d_a_s_i_l_v_a_ns at netcabo.pt> wrote:
>> Hi!
>>
...

> Read the entire file in binary mode, and figure out which parts are
> text and how they're encoded (possibly ASCII or UTF-8). Then take just
> those snippets, and decode them. Something like this:
> 
> data = open("some_file", "rb")
> text_part = data[2718:3142]
> decoded_text = text_part.decode("utf-8")
> 
> That'll give you a usable Unicode string, assuming you have your
> offsets and encoding correct.
> 

Thanks Chris. Please read my response to Dave.





More information about the Python-list mailing list