w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Printing Extended-Ascii Characters In Python 3 In Both Windows and Linux

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

dic = {
'\' : b'xe2x95x9a',
'-'  : b'xe2x95x90',
'/'  : b'xe2x95x9d',
'|'  : b'xe2x95x91',
'+'  : b'xe2x95x94',
'%'  : b'xe2x95x97',
}

def decode(x):
    return (''.join(dic.get(i, i.encode('utf-8')).decode('utf-8') for i in
x))

print(decode('+------------------------------------%'))
print(decode('|           Hello World!             |'))
print(decode('\------------------------------------/'))

Windows:

C:Temp>python temp.py
╔════════════════════════════════════╗
║           Hello World!             ║
╚════════════════════════════════════╝

Linux:

$ python3 temp.py 
╔════════════════════════════════════╗
║           Hello World!             ║
╚════════════════════════════════════╝




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.