0

I'm trying to remove last character with [:-1] from the words that aren't written in latin alphabet (header has # -*- coding: utf-8 -*- set) and removed character gets replaced with ? in terminal output. Any suggestions?

code example:

# -*- coding: utf-8 -*-

word = "სკამი"[:-1]
print word

output in terminal

სკამ?
ikechi
  • 329
  • 1
  • 9
  • possible duplicate of [Why doesn't my terminal output unicode characters properly?](http://stackoverflow.com/questions/12649896/why-doesnt-my-terminal-output-unicode-characters-properly) – max Feb 10 '15 at 21:01
  • Without any code example demonstrating your issue this is not really answerable. – Martijn Pieters Feb 10 '15 at 21:04
  • 2
    @max: No, I think the OP has a *bytestring* and removed one byte from a multi-byte character. That would make the bytestring *invalid*, not just unprintable on a terminal due to a encoding conflict. – Martijn Pieters Feb 10 '15 at 21:05
  • See the updated question with the code. – ikechi Feb 10 '15 at 21:11
  • ah, true, @MartijnPieters. code example makes it look more that way :) – max Feb 10 '15 at 21:13

1 Answers1

1

Stop using bytestrings.

print "სკამი".decode('utf-8')[:-1]
print u"სკამი"[:-1]
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358