Den 2016-09-22 skrev Peter Otten <__pete...@web.de>: > Martin Schöön wrote: >> >> I am not sure I answer your questions since I am not quite sure I >> understand it but here goes: The complete file is UTF-8 encoded as >> that is how Geany is set up to create new files (I just checked). > > When the encoding used for the file and the encoding used by the terminal > differ the output of non-ascii characters gets messed up. Example script: > > # -*- coding: iso-8859-15 -*- > > print "first unicode:" > print u"Schöön" > > print "then bytes:" > print "Schöön" > > When I dump that in my UTF-8 terminal all "ö"s are lost because it gets the > invalid byte sequence b"\xf6" rather than the required b"\xc3\xb6": > > $ cat demo.py > # -*- coding: iso-8859-15 -*- > > print "first unicode:" > print u"Sch��n" > > print "then bytes:" > print "Sch��n" > > But when I run the code: > > $ python demo.py > first unicode: > Schöön > then bytes: > Sch��n > > There are other advantages, too: > >>>> print "Schöön".upper() > SCHööN >>>> print u"Schöön".upper() > SCHÖÖN >>>> print "Schöön"[:4] > Sch� >>>> print u"Schöön"[:4] > Schö > Cool :-) Thanks for the education.
/Martin -- https://mail.python.org/mailman/listinfo/python-list