(Feb-16-2019, 08:31 PM)nikos Wrote: Still i cannot understand WHY it reads the database names like that, instead of their normal Greek names.Is it you have put data into DB,or it is an exiting DB?
MySQL i think store as latin-1 default,if not doing anything like
charset='utf8mb4'
.Yes MySQL has own stupid encoding
utf8mb4
to have proper utf8 support.Look at SO and utf8 data on latin1 tables.
I do not use MySQL if have choice,always PostgreSQL or SQLite for simpler stuff.
Quote:Raw output of names is:The it should not be a problem in you running Python 3,as done a couple of times in this post.
Put in this in script:
import sys print(sys.executable)Python 3.7:
items = ['Alexander Lepsveridze', 'John Comeau', '\xce\x86\xce\xba\xce\xb7\xcf\x82 \xce\xa4\xcf\x83\xce\xb9\xce\xac\xce\xbc\xce\xb7\xcf\x82', '\xce\x8c\xce\xbc\xce\xb9\xce\xbb\xce\xbf\xcf\x82 \xce\xa4\xcf\x83\xce\xbf\xcf\x84\xcf\x85\xce\xbb\xce\xaf\xce\xbf\xcf\x85'] names = [s.encode('latin1').decode('utf8') for s in items] print(names)
Output:λ python uni1.py
C:\python37\python.exe
['Alexander Lepsveridze', 'John Comeau', 'Άκης Τσιάμης', 'Όμιλος Τσοτυλίου']
Running same code in Python 2.7,and it fails.λ py -2.7 uni1.py C:\Python27\python.exe Traceback (most recent call last): File "uni1.py", line 7, in <module> names = [s.encode('latin1').decode('utf8') for s in items] UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 0: ordinal not in range(128)Fix so it also work in Python 2.7.
# -*- coding: utf-8 -*- import sys print(sys.executable) items = ['Alexander Lepsveridze', 'John Comeau', '\xce\x86\xce\xba\xce\xb7\xcf\x82 \xce\xa4\xcf\x83\xce\xb9\xce\xac\xce\xbc\xce\xb7\xcf\x82', '\xce\x8c\xce\xbc\xce\xb9\xce\xbb\xce\xbf\xcf\x82 \xce\xa4\xcf\x83\xce\xbf\xcf\x84\xcf\x85\xce\xbb\xce\xaf\xce\xbf\xcf\x85'] names = [s.decode('utf8') for s in items] print(names) for name in names: print(name)
Output:py -2.7 uni1.py
C:\Python27\python.exe
[u'Alexander Lepsveridze', u'John Comeau', u'\u0386\u03ba\u03b7\u03c2 \u03a4\u03c3\u03b9\u03ac\u03bc\u03b7\u03c2', u'\u038c\u03bc\u03b9\u03bb\u03bf\u03c2 \u03a4\u03c3\u03bf\u03c4\u03c5\u03bb\u03af\u03bf\u03c5']
Alexander Lepsveridze
John Comeau
Άκης Τσιάμης
Όμιλος Τσοτυλίου