"convert" string to bytes without changing data (encoding)

John Nagle nagle at animats.com
Wed Mar 28 21:30:49 CEST 2012


On 3/28/2012 10:43 AM, Peter Daum wrote:
> On 2012-03-28 12:42, Heiko Wundram wrote:
>> Am 28.03.2012 11:43, schrieb Peter Daum:

> The longer story of my question is: I am new to python (obviously), and
> since I am not familiar with either one, I thought it would be advisory
> to go for python 3.x. The biggest problem that I am facing is, that I
> am often dealing with data, that is basically text, but it can contain
> 8-bit bytes. In this case, I can not safely assume any given encoding,
> but I actually also don't need to know - for my purposes, it would be
> perfectly good enough to deal with the ascii portions and keep anything
> else unchanged.

    So why let the data get into a "str" type at all? Do everything
end to end with "bytes" or "bytearray" types.

				John Nagle



More information about the Python-list mailing list