Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

D'Arcy Cain darcy at VybeNetworks.com
Fri Aug 28 09:36:50 EDT 2020


On 2020-08-28 08:30, Richard Damon wrote:
> This might be one of the cases where Python 2's lack handling of string
> vs bytes was an advantage.

For English speaking Americans.

> Python2 handled that sort of case quite easily. Python 3 on the other
> hand, will have issue converting the byte message to a string, since
> there isn't a single encoding that you could use for all of it all the
> time. This being 'fussier' does make sure that the program is handling
> all the text 'properly', and would be helpful if some of the patterns
> being checked for contained 'extended' (non-ASCII) characters.
> 
> One possible solution in Python3 is to decode the byte string using an
> encoding that allows all 256 byte values, so it won't raise any encoding
> errors, just give your possibly non-sense characters for non-ASCII text.

Or simply handle the errors in the way that makes sense for your
requirements.  Check the section on error handling here:

https://www.askpython.com/python/string/python-encode-and-decode-functions

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
A unit of Excelsior Solutions Corporation - Propelling Business Forward
http://www.VybeNetworks.com/
IM:darcy at VybeNetworks.com VoIP: sip:darcy at VybeNetworks.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20200828/07ca8d64/attachment.sig>


More information about the Python-list mailing list