0

I am using Sublime Text.

I want to print the s2, s3 and s4 variables:

s2 = '∞⟀⟁⟂⟃⟄⟇⟈⟉⟊⟐⟑⟒⟓⟔⟕⟖⟗⟘⟙⟚⟛'

s3 = 'αßáàåäæçéèêíìîñóòôöøúùüž'

s4 = '╵╷╹╻│▏┃┆┇┊╎┋╿╽⌞⌟⌜⌝⌊⌋⌈⌉⌋┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛'

print(s2,s3,s4)

But the print statement causes a UnicodeEncodeError:

UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-21: character maps to

Sean Mickey
  • 7,618
  • 2
  • 32
  • 58
IIX 61
  • 17
  • 7

4 Answers4

1

No matter which editor you use or which OS you use, this will always work. simply using sys.stdout.buffer.write() which is one of the best practices.

import sys 

s2 = '∞⟀⟁⟂⟃⟄⟇⟈⟉⟊⟐⟑⟒⟓⟔⟕⟖⟗⟘⟙⟚⟛'
s3 = 'αßáàåäæçéèêíìîñóòôöøúùüž'
s4 = '╵╷╹╻│▏┃┆┇┊╎┋╿╽⌞⌟⌜⌝⌊⌋⌈⌉⌋┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛'

x = s2.encode('utf8')
y = s3.encode('utf8')
z = s4.encode('utf8')

# you can use loops if you want, python is fun!
sys.stdout.buffer.write(x)
print("")
sys.stdout.buffer.write(y)
print("")
sys.stdout.buffer.write(z)
print("")

output:

∞⟀⟁⟂⟃⟄⟇⟈⟉⟊⟐⟑⟒⟓⟔⟕⟖⟗⟘⟙⟚⟛
αßáàåäæçéèêíìîñóòôöøúùüž
╵╷╹╻│▏┃┆┇┊╎┋╿╽⌞⌟⌜⌝⌊⌋⌈⌉⌋┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛
Jiya
  • 745
  • 8
  • 19
0

You can use .encode("utf-8") to string.
For example s2.encode("utf-8") that worked for me.

Techey
  • 19
  • 3
  • unreadable: b'\xe2\x88\x9e\xe2\x9f\x80\xe2\x9f\x81\xe2\x9f\x82\xe2\x9f\x83\xe2\x9f\x84\xe2\x9f\x87\xe2\x9f\x88\xe2\x9f\x89\xe2\x9f\x8a\xe2\x9f\x90\xe2\x9f\x91\xe2\x9f\x92\xe2\x9f\x93\xe2\x9f\x94\xe2\x9f\x95\xe2\x9f\x96\xe2\x9f\x97\xe2\x9f\x98\xe2\x9f\x99\xe2\x9f\x9a\xe2\x9f\x9b' – IIX 61 Jan 23 '21 at 06:11
  • 2
    @Techey encode turns the string into bytes. Why you are suggesting so? – Epsi95 Jan 23 '21 at 06:12
  • @llX 61 I thought your problem was similar to [this](https://github.com/llSourcell/twitter_sentiment_challenge/issues/1) thread. Also my problem was not exactly same but it worked for me, so I suggested – Techey Jan 23 '21 at 06:19
  • I am use sublim text. – IIX 61 Jan 23 '21 at 06:20
0

try with UTF-8 stander format with sublime text. it work for me with sublime. file format like that file save as test3.py

#-*- mode: python -*-
# -*- coding: utf-8 -*-


s2 = '∞⟀⟁⟂⟃⟄⟇⟈⟉⟊⟐⟑⟒⟓⟔⟕⟖⟗⟘⟙⟚⟛'
s3 = 'αßáàåäæçéèêíìîñóòôöøúùüž'

s4 = '╵╷╹╻│▏┃┆┇┊╎┋╿╽⌞⌟⌜⌝⌊⌋⌈⌉⌋┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛'
print(s2,s3,s4)

output:

python3 test3.py 
∞⟀⟁⟂⟃⟄⟇⟈⟉⟊⟐⟑⟒⟓⟔⟕⟖⟗⟘⟙⟚⟛ αßáàåäæçéèêíìîñóòôöøúùüž ╵╷╹╻│▏┃┆┇┊╎┋╿╽⌞⌟⌜⌝⌊⌋⌈⌉⌋┌┍┎┏┐┑┒┓└┕┖┗┘┙┚┛
Jignasha Royala
  • 1,032
  • 10
  • 27
0

I used sublime text and its showing me this error. But when I use Thonny python IDE it shows me very well.

IIX 61
  • 17
  • 7