Least-lossy string.encode to us-ascii?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Sep 13 23:49:00 EDT 2012


On Thu, 13 Sep 2012 16:26:07 -0500, Tim Chase wrote:

> I've got a bunch of text in Portuguese and to transmit them, need to
> have them in us-ascii (7-bit).

That could mean two things:

1) "The receiver is incapable of dealing with Unicode in 2012, which is 
frankly appalling, but what can I do about it?"

2) "The transport mechanism I use to transmit the data is only capable of 
dealing with 7-bit ASCII strings, which is sad but pretty much standard."

In the case of 1), I suggest you look at the Unicode Hammer, a.k.a. "The 
Stupid American":

http://code.activestate.com/recipes/251871

and especially the very many useful comments.


In the case of 2), just binhex or uuencode your data for transport.



-- 
Steven



More information about the Python-list mailing list