utf8_issues.html


001| ####################################################################################################
002| from os import path
003| ####################################################################################################
004| BasePath = r'C:\CJS\prj\Python\app'
005| 
006| 
007| ##================================================================================================##
008| def utf8_errors (s_in, codepage='cp1250', encoding='utf-8'):
009|     '''For working with UTF-8 issues.'''
010|     bs = s_in.encode(encoding)
011|     s_out = bs.decode(codepage)
012|     print()
013|     print(s_in)
014|     print()
015|     print(' '.join(['%02x'%b for b in bs]))
016|     print()
017|     print(s_out)
018|     print()
019|     return (s_out, bs, s_in)
020| 
021| ##================================================================================================##
022| def demo_utf8_errors ():
023|     # Should only be opened in IDLE (gvim will wreck Unicode strings).
024|     s1 = r'I didn’t imagine that! Or think to ask, “When was that?”'
025|     utf8_errors(s1)
026| 
027| 
028| ####################################################################################################
029| '''eof'''
030|