Re: Yield after the return in Python function.

2021-04-05 Thread Terry Reedy
On 4/5/2021 3:32 PM, Chris Angelico wrote: On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy wrote: Python *could* do the same for expresssions: load 'a' (in this case) once into a register or stack slot and use that value consistently throughout the expression. Replacing the eval with the following

Re: Yield after the return in Python function.

2021-04-05 Thread Dan Stromberg
On Mon, Apr 5, 2021 at 10:46 AM Terry Reedy wrote: > If there were a 'dead > (unreachable) code' exception, a reader or compiler would have to > analyze each use of 'yield' and decide whether it is reachable or not. > It's also subject to how hard the compiler feels like trying in any given rele

Re: Yield after the return in Python function.

2021-04-05 Thread Greg Ewing
On 6/04/21 4:02 am, Terry Reedy wrote: *Any* use of 'yield' in a function makes the function a generator function.  ...  If there were a 'dead (unreachable) code' exception, a reader or compiler would have to analyze each use of 'yield' and decide whether it is reachable or not. It would als

RE: Yield after the return in Python function.

2021-04-05 Thread Avi Gross via Python-list
Terry: ... '__missing__' is new since I learned Python ... With so many new dunder variables added, I am wondering when some dunderhead comes up with: __mifflin__ The documented use paper is: https://theoffice.fandom.com/wiki/Dunder_Mifflin_Paper_Company -Original Message

Re: Matplotlib scale

2021-04-05 Thread Thomas Jollans
On 04/04/2021 20:57, Julien Hofmann wrote: Hi everyone, I've created a code to run a 2D mapping using matplotlib from a .csv file. I've tried to set the maximum color (red) of the scale as 80% of the maximum value and not as the maximum value of my .csv file. Does someone know how to modify th

Re: Matplotlib scale

2021-04-05 Thread Julien Hofmann
Le lundi 5 avril 2021 à 21:50:49 UTC+2, David Lowry-Duda a écrit : Thank you for your response! I just tried it but it doesn't make what I want. Bassically, I would like to not put any color for every values above 0.8 times the maximum value (ie. 488). Hence, the ''maximum'' color (ie. red) woul

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Chris Angelico
On Tue, Apr 6, 2021 at 5:36 AM Rob Cliffe via Python-list wrote: > > > > On 05/04/2021 18:33, Chris Angelico wrote: > > > > Firstly, anything with any variable at all can involve a lookup, which > > can trigger arbitrary code (so "variables which do not occur on the > > LHS" is not sufficient). >

Re: Matplotlib scale

2021-04-05 Thread David Lowry-Duda
Hello, > I've created a code to run a 2D mapping using matplotlib from a .csv > file. > I've tried to set the maximum color (red) of the scale as 80% of the maximum > value and not as the maximum value of my .csv file. > Does someone know how to modify that? If I understand what you're trying t

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
On 05/04/2021 18:33, Chris Angelico wrote: Firstly, anything with any variable at all can involve a lookup, which can trigger arbitrary code (so "variables which do not occur on the LHS" is not sufficient). Interesting.  I was going to ask: How could you make a variable lookup trigger arbitra

Re: Yield after the return in Python function.

2021-04-05 Thread Chris Angelico
On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy wrote: > > On 4/5/2021 1:53 PM, Chris Angelico wrote: > > On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: > >> *While 'a and not a' == False in logic, in Python it might raise > >> NameError. But that would still mean that it is never True, making > >

Re: Yield after the return in Python function.

2021-04-05 Thread Terry Reedy
On 4/5/2021 1:53 PM, Chris Angelico wrote: On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: *While 'a and not a' == False in logic, in Python it might raise NameError. But that would still mean that it is never True, making 'yield 0' still unreachable. When I wrote that, I knew I might be m

Re: error on os.open API

2021-04-05 Thread Marco Ippolito
> It seems that the os.open API cannot distinguish between a permission error > and the fact that a directory cannot be opened like files. > The following script reproduces the scenario (tested on Python 3.8.2 > (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on > win32) :

Re: error on os.open API

2021-04-05 Thread Chris Angelico
On Tue, Apr 6, 2021 at 3:50 AM Rami Khaldi wrote: > > Hello, > > It seems that the os.open API cannot distinguish between a permission error > and the fact that a directory cannot be opened like files. > The following script reproduces the scenario (tested on Python 3.8.2 > (tags/v3.8.2:7b3ab59,

Re: Yield after the return in Python function.

2021-04-05 Thread Chris Angelico
On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: > *While 'a and not a' == False in logic, in Python it might raise > NameError. But that would still mean that it is never True, making > 'yield 0' still unreachable. > And even just the lookup can have side effects, if your code is pathologicall

error on os.open API

2021-04-05 Thread Rami Khaldi
Hello, It seems that the os.open API cannot distinguish between a permission error and the fact that a directory cannot be opened like files. The following script reproduces the scenario (tested on Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32) :

Re: Yield after the return in Python function.

2021-04-05 Thread Terry Reedy
On 4/5/2021 8:25 AM, Bischoop wrote: The return suspends the function execution so how is it that in below example I got output: def doit(): return 0 yield 0 print(doit()) *Any* use of 'yield' in a function makes the function a generator function. This is a simple rule that

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Chris Angelico
On Tue, Apr 6, 2021 at 3:26 AM Rob Cliffe via Python-list wrote: > > > > On 05/04/2021 17:52, Chris Angelico wrote: > > On Tue, Apr 6, 2021 at 2:32 AM Rob Cliffe via Python-list > > wrote: > >> > >> > >> It doesn't appear to, at least not always. In Python 3.8.3: > >> from dis import dis > >> de

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
On 05/04/2021 17:52, Chris Angelico wrote: I don't understand.  What semantic difference could there be between     x = { 1: 2 }    ;    y = [3, 4]   ;   z = (5, 6) and     x, y, z = { 1:2 }, [3, 4], (5, 6) ?  Why is it not safe to convert the latter to the former? But I withdraw "set" from my "

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
On 05/04/2021 17:52, Chris Angelico wrote: On Tue, Apr 6, 2021 at 2:32 AM Rob Cliffe via Python-list wrote: It doesn't appear to, at least not always. In Python 3.8.3: from dis import dis def f(): x = 1 ; y = 2 def g(): (x,y) = (1,2) dis(f) dis(g) Output: 2 0 LOAD_CONST

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Chris Angelico
On Tue, Apr 6, 2021 at 2:32 AM Rob Cliffe via Python-list wrote: > > > > It doesn't appear to, at least not always. In Python 3.8.3: > from dis import dis > def f(): x = 1 ; y = 2 > def g(): (x,y) = (1,2) > dis(f) > dis(g) > > Output: >2 0 LOAD_CONST 1 (1) >

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
On 05/04/2021 00:47, dn via Python-list wrote: On 04/04/2021 01.00, Rob Cliffe via Python-list wrote: On 03/04/2021 04:09, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-04-03 at 02:41:59 +0100, Rob Cliffe via Python-list wrote: x1 = 42; y1 =  3;  z1 = 10 x2 = 41; y2 = 12;

Re: Yield after the return in Python function.

2021-04-05 Thread Frank Millman
On 2021-04-05 2:25 PM, Bischoop wrote: The return suspends the function execution so how is it that in below example I got output: def doit(): return 0 yield 0 print(doit()) The 'yield' in the function makes the function a 'generator' function. 'Calling' a generator functio

Yield after the return in Python function.

2021-04-05 Thread Bischoop
The return suspends the function execution so how is it that in below example I got output: def doit(): return 0 yield 0 print(doit()) -- https://mail.python.org/mailman/listinfo/python-list

Re: Using pytest, sometimes does not capture stderr

2021-04-05 Thread Peter Otten
On 05/04/2021 06:25, Cameron Simpson wrote: If you truly need to test msg() _without_ the file= parameter, you could monkey patch module_2: old_MSG_DESTINATION = module_2.MSG_DESTINATION module_2.MSG_DESTINATION = sys.stderr # now the module_2 module has an updated reference for