Re: Convert a list with wrong encoding to utf8

2019-02-15 Thread Piet van Oostrum
vergos.niko...@gmail.com writes: > Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 8:56:31 μ.μ. UTC+2, ο χρήστης MRAB έγραψε: > >> It doesn't have a 'b' prefix, so either it's Python 2 or it's a Unicode >> string that was decoded wrongly from the bytes. > > Yes it doesnt have the 'b' prefix so that hexadecimal

Re: Convert a list with wrong encoding to utf8

2019-02-15 Thread Gregory Ewing
vergos.niko...@gmail.com wrote: [python] con = pymysql.connect( db = 'clientele', user = 'vergos', passwd = '**', charset = 'utf8' ) cur = con.cursor() [/python] From that i understand that the names being fetched from the db to pyhton script are being fetced as utf8, right? No, I don't th

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread Gregory Ewing
vergos.niko...@gmail.com wrote: I just tried: names = tuple( [s.encode('latin1').decode('utf8') for s in names] ) but i get UnicodeEncodeError('latin-1', 'Άκης Τσιάμης', 0, 4, 'ordinal not in range(256)') This suggests that the string you're getting from the database *has* already been correc

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread Michael Torrie
On 02/14/2019 12:02 PM, vergos.niko...@gmail.com wrote: > Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 8:16:40 μ.μ. UTC+2, ο χρήστης Calvin > Spealman έγραψε: >> If you see something like this >> >> '\xce\x86\xce\xba\xce\xb7\xcf\x82 >> \xce\xa4\xcf\x83\xce\xb9\xce\xac\xce\xbc\xce\xb7\xcf\x82' >> >> then you d

RE: Convert a list with wrong encoding to utf8

2019-02-14 Thread David Raymond
on-list-bounces+david.raymond=tomtom@python.org] On Behalf Of vergos.niko...@gmail.com Sent: Thursday, February 14, 2019 2:56 PM To: python-list@python.org Subject: Re: Convert a list with wrong encoding to utf8 Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 8:56:31 μ.μ. UTC+2, ο χρήστης MRAB έγραψε: > It doesn&#

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread vergos . nikolas
I'm using Python3 and pymysql and already have charset presnt [python] con = pymysql.connect( db = 'clientele', user = 'vergos', passwd = '**', charset = 'utf8' ) cur = con.cursor() [/python] From that i understand that the names being fetched from the db to pyhton script are being fetced a

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread vergos . nikolas
Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 8:56:31 μ.μ. UTC+2, ο χρήστης MRAB έγραψε: > It doesn't have a 'b' prefix, so either it's Python 2 or it's a Unicode > string that was decoded wrongly from the bytes. Yes it doesnt have the 'b' prefix so that hexadecimal are representation of strings and not rep

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread Νίκος Βέργος
con = pymysql.connect( db = 'clientele', user = 'vergos', passwd = '***', charset = 'utf8' ) cur = con.cursor() Στις Πέμ, 14 Φεβ 2019 στις 9:13 μ.μ., ο/η Igor Korot έγραψε: > Hi, > > On Thu, Feb 14, 2019 at 1:10 PM wrote: > > > > Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 8:16:40 μ.μ. UTC+2, ο χρήστη

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread vergos . nikolas
Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 9:14:08 μ.μ. UTC+2, ο χρήστης Igor Korot έγραψε: > Hi, > > On Thu, Feb 14, 2019 at 1:10 PM wrote: > > > > Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 8:16:40 μ.μ. UTC+2, ο χρήστης Calvin > > Spealman έγραψε: > > > If you see something like this > > > > > > '\xce\x86\xce\xb

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread Igor Korot
Hi, On Thu, Feb 14, 2019 at 1:10 PM wrote: > > Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 8:16:40 μ.μ. UTC+2, ο χρήστης Calvin > Spealman έγραψε: > > If you see something like this > > > > '\xce\x86\xce\xba\xce\xb7\xcf\x82 > > \xce\xa4\xcf\x83\xce\xb9\xce\xac\xce\xbc\xce\xb7\xcf\x82' > > > > then you don'

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread vergos . nikolas
Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 8:16:40 μ.μ. UTC+2, ο χρήστης Calvin Spealman έγραψε: > If you see something like this > > '\xce\x86\xce\xba\xce\xb7\xcf\x82 > \xce\xa4\xcf\x83\xce\xb9\xce\xac\xce\xbc\xce\xb7\xcf\x82' > > then you don't have a string, you have raw bytes. You don't "encode" bytes

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread MRAB
On 2019-02-14 18:16, Calvin Spealman wrote: If you see something like this '\xce\x86\xce\xba\xce\xb7\xcf\x82 \xce\xa4\xcf\x83\xce\xb9\xce\xac\xce\xbc\xce\xb7\xcf\x82' then you don't have a string, you have raw bytes. You don't "encode" bytes, you decode them. If you know this is already encoded

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread Calvin Spealman
If you see something like this '\xce\x86\xce\xba\xce\xb7\xcf\x82 \xce\xa4\xcf\x83\xce\xb9\xce\xac\xce\xbc\xce\xb7\xcf\x82' then you don't have a string, you have raw bytes. You don't "encode" bytes, you decode them. If you know this is already encoded as UTF-8 then you just need the decode('utf8'

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread vergos . nikolas
Τη Πέμπτη, 14 Φεβρουαρίου 2019 - 6:45:29 μ.μ. UTC+2, ο χρήστης Calvin Spealman έγραψε: > You can only decode FROM the same encoding you've encoded TO. Any decoding > must know the input it receives follows the rules of its encoding scheme. > latin1 is not utf8. > > However, in your case, you aren

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread Calvin Spealman
You can only decode FROM the same encoding you've encoded TO. Any decoding must know the input it receives follows the rules of its encoding scheme. latin1 is not utf8. However, in your case, you aren't seeing problem with the decoding. That step is never reached. It is failing to encode the stri

Re: Convert a list with wrong encoding to utf8

2019-02-14 Thread Chris Angelico
On Fri, Feb 15, 2019 at 3:41 AM wrote: > > Hello, i have tried the following to chnage encoding to utf8 because for some > reason it has changed regarding list names > > [python] > #populate client listing into list > names.append( name ) > > > names.appe

Convert a list with wrong encoding to utf8

2019-02-14 Thread vergos . nikolas
Hello, i have tried the following to chnage encoding to utf8 because for some reason it has changed regarding list names [python] #populate client listing into list names.append( name ) names.append( '' ) names.sort() for name in names: