Friday 15 January 2010

Printing Extended-Ascii Characters In Python 3 In Both Windows and Linux -


I get a few questions that look like this - but despite my best efforts I can not get it Any solution to work

I am trying to print extended ASCI characters to create an old text-based menu. Here is my original code:

  print ('' '' '' '' '' '' '' '' '' '' '' ' A ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? A ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? One is a ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? a '???' ') Print (' 'Hello world! One' ??? '') print ("one" a "????" a ???? one ???? one ???? one ???? A ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? A ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? If I run a .py file, then my output looks like this:    P> 
  ?????????????? Hello world !? ?????????????? I am using Python 3.3.1 and need a solution that works in both Windows and Linux 'just work' I have tried using  chcp 65001  in my Windows console without any luck.  

I tried to use 'setdefaultencoding' but I believe it does not apply to python 3 anymore.

There should be a better way, but about something like this:

  dike = {'\\': b '\ xe2 \ x95 \ x9a', '-': b '\ xe2 \ x95 \ x90', '/': b '\ xe2 \ x95 \ x9d', '| 'B' \ xe2 \ x95 \ x91 ',' + ': b' \ xe2 \ x95 \ x94 ','% ': b' \ xe2 \ x95 \ x97 ',} DEP decode (x): return (' '.x (i, i.encode (' utf-8 ')). For decode (' utf-8 ') for x) print (decode (' --------- ----- ----------------------% ')) Print (Decode (' | Hello World! | ')) Print (Decode (' \ '\ --- --------------------------------- / '))   

Windows:

  C: \ Temp & gt; Python temp.py a '' '' '' '' '??? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One? ??? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One? ??? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One? ??? One ???? One ???? a???? Hello world! a???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ????   

Linux:

  $ python3 temp.py one '' a '???? Line ??? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One? ??? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One? ??? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One? ??? One ???? One ???? One ???? a???? Hello world! a???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ???? One ????    

No comments:

Post a Comment