简体   繁体   中英

How print non-latin letters?

I have a simple script parse_dict_pl.py:

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

f = open('polish.txt','r')
print "Polish letters: ęóąśłżźćń"
for l in f:
        print l

File polish.txt contains polish letters: ęóąśłżźćń
I run script from windows command line as follows:

python parse_dict_pl.py

and the result is:

Polish letters: ęóąśłżźćń
ęóąśłżźćń

How can I properly print polish letters hardcoded in the script and loaded from file?

Pawel

TRY:

# -*- coding: utf-8 -*-
from unidecode import unidecode

text = u'ęóąśłżźćń'
result = ''

for i in text:
   try:
     result += i.encode('1252').decode('1252')
   except (UnicodeEncodeError, UnicodeDecodeError):
    result += unidecode(i)

print result

It's producing the output:

eóaslzzcn

You have to install unidecode library. Get it from library reference
I've taken the polish letters within a variable,you can try it according to your need. Hope it'll help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM