Re: newb question about @property

2017-10-01 Thread Bill
Steve D'Aprano wrote: [1] Technically, the interpreter knows nothing about properties. What it cares about is *descriptors*. Properties are just one kind of descriptor, as are methods. But I'm intentionally not talking about the gory details of descriptors. Feel free to ask if you care, but hone

Re: newb question about @property

2017-10-01 Thread Steve D'Aprano
On Sun, 1 Oct 2017 05:46 pm, Bill wrote: > If you were going to show non-Python users, say science undergraduates > and faculty, that Python is an interesting tool (in 45 minutes), would > one delve into descriptors? Hell no :-) I think there's a hierarchy of difficulty/complexity/mind-boggling

Re: newb question about @property

2017-10-01 Thread Thomas Jollans
On 01/10/17 03:52, Stefan Ram wrote: > MRAB writes: >> raise ValueError("Temperature below -273 is not possible") > -273.15 > Either way, that depends. https://en.wikipedia.org/wiki/Negative_temperature#Examples -- https://mail.python.org/mailman/listinfo/python-list

Escape-Sequenzen in einem String identifizieren

2017-10-01 Thread Ulrich Goebel
Hallo, ich lese mit Python aus einer PostgreSQL-Datenbank strings (SQL-Typ: text), die über LibreOffice dort hinein geschrieben werden. Diese Strings können Zeilenschaltungen enthalten, von denen ich aber nicht weiß, wie sie kodiert sind: vielleicht \n, \r, \n\r, \r\n oder sonstwie. Um das h

Re: newb question about @property

2017-10-01 Thread MRAB
On 2017-10-01 02:52, Stefan Ram wrote: MRAB writes: raise ValueError("Temperature below -273 is not possible") -273.15 I think you've trimmed a little too much. In my reply I was only copying what someone else had written. -- https://mail.python.org/mailman/listinfo/python-list

Re: Escape-Sequenzen in einem String identifizieren

2017-10-01 Thread Thomas Jollans
On 01/10/17 19:20, Ulrich Goebel wrote: > Hallo, > > ich lese mit Python aus einer PostgreSQL-Datenbank strings (SQL-Typ: > text), die über LibreOffice dort hinein geschrieben werden. Diese > Strings können Zeilenschaltungen enthalten, von denen ich aber nicht > weiß, wie sie kodiert sind: vielleic

Re: Escape-Sequenzen in einem String identifizieren

2017-10-01 Thread MRAB
On 2017-10-01 18:20, Ulrich Goebel wrote: Hallo, ich lese mit Python aus einer PostgreSQL-Datenbank strings (SQL-Typ: text), die über LibreOffice dort hinein geschrieben werden. Diese Strings können Zeilenschaltungen enthalten, von denen ich aber nicht weiß, wie sie kodiert sind: vielleicht \n,

Re: newb question about @property

2017-10-01 Thread Stephan Houben
Op 2017-10-01, Bill schreef : > I watched an example on YouTube where someone wrote a simple descriptor > ("@Time_it) to output the amount of time that it took ordinary functions > to complete.To be honest, I AM interested in descriptors. Are you sure you are not confusing deSCRIPTtors and

Re: newb question about @property

2017-10-01 Thread Stephan Houben
Op 2017-10-01, Bill schreef : > Steve D'Aprano wrote: >> >> [1] Technically, the interpreter knows nothing about properties. What >> it cares about is *descriptors*. Properties are just one kind of >> descriptor, as are methods. But I'm intentionally not talking about >> the gory details of descrip

on a very slow function

2017-10-01 Thread Daniel Bastos
def make_sequence_non_recursive(N, x0 = 2, c = -1): "What's wrong with this function? It's very slow." last = x0 def sequence(): nonlocal last next = last last = last**2 + c return next % N return sequence It crawls pretty soon. Please advise? Thank you. >>> f = make_se

Re: on a very slow function

2017-10-01 Thread Chris Angelico
On Mon, Oct 2, 2017 at 8:27 AM, Daniel Bastos wrote: > def make_sequence_non_recursive(N, x0 = 2, c = -1): > "What's wrong with this function? It's very slow." > last = x0 > def sequence(): > nonlocal last > next = last > last = last**2 + c > return next % N > return seque

Re: newb question about @property

2017-10-01 Thread Bill
Steve D'Aprano wrote: On Sun, 1 Oct 2017 05:46 pm, Bill wrote: If you were going to show non-Python users, say science undergraduates and faculty, that Python is an interesting tool (in 45 minutes), would one delve into descriptors? Hell no :-) Oops, I see I used the word "descriptor", where I

Re: on a very slow function

2017-10-01 Thread Daniel Bastos
Chris Angelico writes: > On Mon, Oct 2, 2017 at 8:27 AM, Daniel Bastos wrote: >> def make_sequence_non_recursive(N, x0 = 2, c = -1): >> "What's wrong with this function? It's very slow." >> last = x0 >> def sequence(): >> nonlocal last >> next = last >> last = last**2 + c >>

Re: newb question about @property

2017-10-01 Thread Bill
Stephan Houben wrote: Op 2017-10-01, Bill schreef : I watched an example on YouTube where someone wrote a simple descriptor ("@Time_it) to output the amount of time that it took ordinary functions to complete.To be honest, I AM interested in descriptors. Are you sure you are not confusing d

Re: on a very slow function

2017-10-01 Thread Ben Bacarisse
Daniel Bastos writes: > def make_sequence_non_recursive(N, x0 = 2, c = -1): > "What's wrong with this function? It's very slow." > last = x0 > def sequence(): > nonlocal last > next = last > last = last**2 + c > return next % N > return sequence > > It crawls pretty soon.

Re: newb question about @property

2017-10-01 Thread Bill
Steve D'Aprano wrote: The definitive explanation of descriptors is here: https://docs.python.org/3/howto/descriptor.html Thank you! It is next on my list. Then I'll try that Circle problem you mentioned as an exercise last night! I don't expect run into any difficulties. : ) -- https:/

Re: newb question about @property

2017-10-01 Thread Chris Angelico
On Mon, Oct 2, 2017 at 9:47 AM, Bill wrote: > Stephan Houben wrote: >> >> Op 2017-10-01, Bill schreef : >>> >>> I watched an example on YouTube where someone wrote a simple descriptor >>> ("@Time_it) to output the amount of time that it took ordinary functions >>> to complete.To be honest, I A

Re: on a very slow function

2017-10-01 Thread Chris Angelico
On Mon, Oct 2, 2017 at 9:22 AM, Daniel Bastos wrote: > Chris Angelico writes: > >> For a start, it should probably be implemented as a generator. > > Maybe something like this? > > def make_generator(N, last = 2, c = -1): > while True: > yield last > last = (last**2 + c) % N Yeah, that

Re: on a very slow function

2017-10-01 Thread Steve D'Aprano
On Mon, 2 Oct 2017 09:49 am, Ben Bacarisse wrote: > Daniel Bastos writes: > >> def make_sequence_non_recursive(N, x0 = 2, c = -1): >> "What's wrong with this function? It's very slow." >> last = x0 >> def sequence(): >> nonlocal last >> next = last >> last = last**2 + c >>

Re: on a very slow function

2017-10-01 Thread Chris Angelico
On Mon, Oct 2, 2017 at 11:34 AM, Steve D'Aprano wrote: >> change it to >> >> last = (last**2 + c) % N >> return next > > Better: > > last = (pow(last, 2, N) + (2 % N)) % N > > will almost certainly be faster for large values of last. I think possibly you mean (c % N) in the middle the

Re: on a very slow function

2017-10-01 Thread Ben Bacarisse
Steve D'Aprano writes: > On Mon, 2 Oct 2017 09:49 am, Ben Bacarisse wrote: > >> Daniel Bastos writes: >> >>> def make_sequence_non_recursive(N, x0 = 2, c = -1): >>> "What's wrong with this function? It's very slow." >>> last = x0 >>> def sequence(): >>> nonlocal last >>> next = l

Re: newb question about @property

2017-10-01 Thread breamoreboy
On Sunday, October 1, 2017 at 6:47:34 PM UTC+1, MRAB wrote: > On 2017-10-01 02:52, Stefan Ram wrote: > > MRAB writes: > >>raise ValueError("Temperature below -273 is not possible") > > > >-273.15 > > > I think you've trimmed a little too much. In my reply I was only copying > what someone el

Re: on a very slow function

2017-10-01 Thread Steve D'Aprano
On Mon, 2 Oct 2017 12:00 pm, Ben Bacarisse wrote: >> Better: >> >> last = (pow(last, 2, N) + (2 % N)) % N > > You meant c rather than 2, I think. Oops, yes, that was a typo. > And I'm not convinced all the %Ns > are worth while. They are all necessary. py> (2**75 + 7) % 12 # Expected val

Re: on a very slow function

2017-10-01 Thread Christian Gollwitzer
Am 01.10.17 um 23:27 schrieb Daniel Bastos: def make_sequence_non_recursive(N, x0 = 2, c = -1): "What's wrong with this function? It's very slow." last = x0 def sequence(): nonlocal last next = last last = last**2 + c return next % N return sequence It crawls pre

Re: newb question about @property

2017-10-01 Thread Marko Rauhamaa
Chris Angelico : > Yes, that's correct. The *descriptor* protocol is what allows > "foo.bar" to cause a function to be executed That mechanism allows you to expose data fields in the API. If the implementation later changes, you can emulate the data fields. I must say, though, I have yet to run