Re: Problem : Generator

2019-02-14 Thread Prahallad Achar
How about this List1=[ 1,2,3,4] Rever_gen = ( x*x for x in list1, reversed = True) Rever_gen gets generator object and iterating it now gets reverse order.. Am I correct here? Suggest me On Fri, 15 Feb 2019, 12:33 dieter Prahallad Achar writes: > > How to implement reverse generator > > A gene

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: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Chris Angelico
On Fri, Feb 15, 2019 at 4:15 PM Avi Gross wrote: > > > You shouldn't be testing floats for identity. > > I am not suggesting anyone compare floats. I repeat that a nan is not > anything. Now as a technicality, it is considered a float by the type > command as there is no easy way to make an int th

Re: Problem : Generator

2019-02-14 Thread dieter
Prahallad Achar writes: > How to implement reverse generator A generator generates a sequence of values. The notion "reverse generator" suggests that you have a sequence of values and want to produce it in reverse order. This is not always possible. Consider: def natural(): i = 0 while True

RE: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Avi Gross
Chris, I don't wish to continue belaboring this topic but will answer you and then ignore anything non-essential. You said: > You shouldn't be testing floats for identity. I am not suggesting anyone compare floats. I repeat that a nan is not anything. Now as a technicality, it is considered a f

Re: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Chris Angelico
On Fri, Feb 15, 2019 at 2:37 PM Avi Gross wrote: > But here is a curiosity. The numpy add-on package has a nan that is UNIQUE > so two copies are the same. Read this transcript and see if it might > sometimes even be useful while perhaps confusing the heck out of people who > assume all nans are t

RE: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Avi Gross
Grant, I can see why you may be wondering. You see the nan concept as having a specific spelling using all lowercase and to an extent you are right. As I pointed out. In the context of a string to convert to a float, any upper/lower-case spelling of NaN is accepted. But, to answer you anyway, I

Re: FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Grant Edwards
On 2019-02-14, Avi Gross wrote: > I experimented a bit: > float("nan ") > nan float(" nan") > Nan float(" nAn") > nan That's curious. I've never seen "Nan" before. What version of Python are you using? -- Grant Edwards grant.b.edwardsYow! NANCY!! Why i

FW: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Avi Gross
Other people have replied well enough with better ways to do this but I am stuck on WHY this was seen as a way to do this at all. The code was: r = float('Nan') while r==float('Nan'): inp = input("Enter a number\n") try: r = float(inp) except ValueError: r = float

Re: Problem : Generator

2019-02-14 Thread Ben Finney
Prahallad Achar writes: > How to implement reverse generator Welcome to the Python forum! That sounds like an interesting problem. Can you describe it more precisely? What should a “reverse generator” actually do (and not do)? Ideally, give an example: * Some code you would maybe expect to cr

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
Next question is how did you _insert_ those names into the database previously? Are the names showing up ok using any other tool to look at them? The error might have been on insert and you're just seeing weird stuff now because of that. Maybe, where instead of giving it the text and letting the

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

Problem : Generator

2019-02-14 Thread Prahallad Achar
How to implement reverse generator It is only passing data in reverse or how it is Yeild always returns next value and is question valid? Thanks and Regards Prahallad -- https://mail.python.org/mailman/listinfo/python-list

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: What's up with Activestate Python?

2019-02-14 Thread Chris Angelico
On Fri, Feb 15, 2019 at 5:11 AM Grant Edwards wrote: > > On 2019-02-14, Liste guru wrote: > > Il 14/02/2019 00:06, Grant Edwards ha scritto: > >> For many, many years I've always installed ActiveState's ActivePython > >> Community edition when forced to use Windows. It has always included > >> .

Re: What's up with Activestate Python?

2019-02-14 Thread Grant Edwards
On 2019-02-14, Liste guru wrote: > Il 14/02/2019 00:06, Grant Edwards ha scritto: >> For many, many years I've always installed ActiveState's ActivePython >> Community edition when forced to use Windows. It has always included >> ... >> I guess it's time to switch to Anaconda or ??? > > I've also

Re: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Joe Pfeiffer
Chris Angelico writes: > > Or even better, use None instead of nan. There's nothing in Python > says you have to (ab)use a floating-point value as a signal. Or use > "while True" and add a break if the exception isn't thrown. Good point. -- https://mail.python.org/mailman/listinfo/python-list

Re: What's up with Activestate Python?

2019-02-14 Thread Liste guru
Il 14/02/2019 00:06, Grant Edwards ha scritto: For many, many years I've always installed ActiveState's ActivePython Community edition when forced to use Windows. It has always included ... I guess it's time to switch to Anaconda or ???     I've also used the ActiveState python, expecially fo

Re: Why float('Nan') == float('Nan') is False

2019-02-14 Thread אורי
> Or even better, use None instead of nan. ++ On Thu, Feb 14, 2019 at 3:26 AM Joe Pfeiffer wrote: > u...@speedy.net writes: > > > There are more integers than odd numbers, and more odd numbers than prime > > numbers. An infinite set may be a subset of another infinite set although > > they may

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: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Chris Angelico
On Fri, Feb 15, 2019 at 3:56 AM Joe Pfeiffer wrote: > > ast writes: > > > Le 13/02/2019 à 14:21, ast a écrit : > >> Hello > >> > >> >>> float('Nan') == float('Nan') > >> False > >> > >> Why ? > >> > >> Regards > >> > > > > Thank you for answers. > > > > If you wonder how I was trapped with it, h

Re: Why float('Nan') == float('Nan') is False

2019-02-14 Thread Joe Pfeiffer
ast writes: > Le 13/02/2019 à 14:21, ast a écrit : >> Hello >> >> >>> float('Nan') == float('Nan') >> False >> >> Why ? >> >> Regards >> > > Thank you for answers. > > If you wonder how I was trapped with it, here > is the failing program. > > > r = float('Nan') > > while r==float('Nan'): >

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: