I'm using Python 2.7.3. My operating system is Windows7(32-bit). In the cmd, I typed this code:
chcp 1254 and I converted decoding system to 1254. But,
#!/usr/bin/env python # -*- coding:cp1254 -*- print "öçışğüÖÇİŞĞÜ" When I ran above codes, I got that output:
÷²■³Íæ̺▄ But when I put u after the print command (print u"öçışğüÖÇİŞĞÜ")
When I edited codes as that:
#!/usr/bin/env python # -*- coding:cp1254 -*- import os a = r"C:\\" b = "ö" print os.path.join(a, b) I got that output:
÷ That's why when I tried
print unicode(os.path.join(a, b)) command. I got that error:
print unicode(os.path.join(a, b)) UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 13: ordinal not in range(128) By trying a different way:
print os.path.join(a, b).decode("utf-8").encode(sys.stdout.encoding) When I tried above code, I got that error:
print os.path.join(a, b).decode("utf-8").encode(sys.stdout.encoding) File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 13: invalid start byte As a result, I can't get rid of this error. How can I solve it ? Thanks.