On 16 August 2016 at 14:57, William ML Leslie <[email protected]> wrote:
> On 16 August 2016 at 14:40, Anthony Briggs <[email protected]> > wrote: > > print("M├┐ h├┤v├¿r├ºr├áft ├«├ƒ f├╗┼él ├Âf ├®├¬l┼ø") > > > > works just fine for me, since you're just printing an internal Python > > string. > > It will work fine unless you're on Mike's machine - if > sys.stdout.encoding is cp850 and you've got unicode_literals imported > (or are using python3), it won't. > That string is translated to a cp1252 character set, so I'd be surprised if it didn't work. OTOH, try utf-8 characters in a Windows Python REPL, and you don't even make it to the end of the string :) print("Mÿ hôvèrçràft îß fûll öf éêls") >The problem is from trying to print a binary string (which is what > > you get from .encode()) as an internal Python string. If you specify an > > encoding, the error goes away: > > > > print("M├┐ h├┤v├¿r├ºr├áft ├«├ƒ f├╗┼él ├Âf > > ├®├¬l┼ø".encode("utf-8").decode("cp1252", "replace")) > > The only reason to encode to utf-8 and then decode from cp1252 is to > fix incorrect input. > > I think you mean .encode("cp1252", "replace").decode("cp1252") > No - the point was to get a binary string that doesn't translate nicely into cp1252, otherwise you don't need the 'replace' parameter. This is Mike's core problem - he's reading bytes from a utf-8 file, and trying to print that to the terminal. Anthony
_______________________________________________ melbourne-pug mailing list [email protected] https://mail.python.org/mailman/listinfo/melbourne-pug
