unicode - How can you print a string using raw_unicode_escape encoding in python 3? -
 In Python 3.x the following code should be: str, not bytes  because with TypeError < Code> encoded ()  return  bytes  and  print ()  are only expected  str . 
  #! __future__ import from / usr / bin / python print_function str2 = "some unicode text" print (str2.encode ('raw_unicode_escape'))    How you can print a Unicode string using By running  print () ? I'm looking for a solution that will work with Python 2.6 or new, which includes 3.x 
updates
 will work with bottom line 3.x It will not work with 2.6,  attribute enters: 'file' object has no attribute 'buffer'  
  sys.stdout.buffer.write (str2 .encode ('raw_unicode_escape'))   
I just use:
  print (str2 if you want the same code in Python 3 and Python 2.6 ( You can use  repr  2.6 and in  ascii  in Python 3, but it is not actually "identical"; -).  
Comments
Post a Comment