Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Tim Chase
From: Tim Chase On 2018-06-23 23:08, Jim Lee wrote: >>> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result what would you expect the result of calling

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Tim Chase
From: Tim Chase On 2018-06-24 05:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, > since this is about your EXPECTATIONS, not what Python actually > does. > > Given this function: > > def test(): > a = 1 > b = 2 > result = [value for

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Ben Finney
From: Ben Finney Paul Moore writes: > On 24 June 2018 at 06:03, Steven D'Aprano > wrote: > > Given this function: > > > > def test(): > > a = 1 > > b = 2 > > result = [value for key, value in locals().items()] > > return result > > > > what would you expect the result of

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Paul Moore
From: Paul Moore On 24 June 2018 at 06:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Antoon Pardon
On 26-06-18 12:39, Steven D'Aprano wrote: > On Tue, 26 Jun 2018 12:04:16 +0200, Antoon Pardon wrote: > >> On 26-06-18 11:22, Steven D'Aprano wrote: >>> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >>> > def test(): > a = 1 > b = 2 > result = [value for key,

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Steven D'Aprano
On Tue, 26 Jun 2018 12:04:16 +0200, Antoon Pardon wrote: > On 26-06-18 11:22, Steven D'Aprano wrote: >> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >> def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result >> [...] >>

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Paul Moore
On 26 June 2018 at 11:09, Chris Angelico wrote: > On Tue, Jun 26, 2018 at 8:04 PM, Antoon Pardon wrote: >> On 26-06-18 11:22, Steven D'Aprano wrote: >>> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >>> > def test(): > a = 1 > b = 2 > result = [value for

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Antoon Pardon
On 26-06-18 12:09, Chris Angelico wrote: > On Tue, Jun 26, 2018 at 8:04 PM, Antoon Pardon wrote: >> On 26-06-18 11:22, Steven D'Aprano wrote: >>> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >>> > def test(): > a = 1 > b = 2 > result = [value for key, value

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Chris Angelico
On Tue, Jun 26, 2018 at 8:04 PM, Antoon Pardon wrote: > On 26-06-18 11:22, Steven D'Aprano wrote: >> On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >> def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result >>

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Antoon Pardon
On 26-06-18 11:22, Steven D'Aprano wrote: > On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: > >>> def test(): >>> a = 1 >>> b = 2 >>> result = [value for key, value in locals().items()] >>> return result > [...] > >> I would expect an UnboundLocalError: local variable

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Steven D'Aprano
On Tue, 26 Jun 2018 10:20:38 +0200, Antoon Pardon wrote: >> def test(): >> a = 1 >> b = 2 >> result = [value for key, value in locals().items()] >> return result [...] > I would expect an UnboundLocalError: local variable 'result' referenced > before assignment. Well, I did say

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-26 Thread Antoon Pardon
On 24-06-18 07:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Jim Lee
From: Jim Lee On 06/23/2018 11:02 PM, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 3:44 PM, Jim Lee wrote: >> >> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >>> I'd like to run a quick survey. There is no right or wrong answer, since >>> this is about your EXPECTATIONS, not what Python

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Jim Lee
From: Jim Lee On 06/23/2018 10:03 PM, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Steven D'Aprano
From: Steven D'Aprano On Sun, 24 Jun 2018 15:18:49 +1000, Chris Angelico wrote: > Personally, I think it should give you [1, 2], the two values from the > function's locals. Thank you, that's the sort of answer I'm looking for. (I'm not saying I didn't read your long and involved analysis,

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Chris Angelico
From: Chris Angelico On Sun, Jun 24, 2018 at 3:03 PM, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 >

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Jim Lee
From: Jim Lee On 06/23/2018 11:16 PM, Chris Angelico wrote: > On Sun, Jun 24, 2018 at 4:08 PM, Jim Lee wrote: >> There are three locals: a, b, and result. Since result cannot be assigned >> a value until the list comp has been evaluated, I would expect the comp to >> return a value of

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Chris Angelico
From: Chris Angelico On Sun, Jun 24, 2018 at 4:08 PM, Jim Lee wrote: > There are three locals: a, b, and result. Since result cannot be assigned > a value until the list comp has been evaluated, I would expect the comp to > return a value of "None" for result. An argument could also be made

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Chris Angelico
From: Chris Angelico On Sun, Jun 24, 2018 at 3:44 PM, Jim Lee wrote: > > > On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >> >> I'd like to run a quick survey. There is no right or wrong answer, since >> this is about your EXPECTATIONS, not what Python actually does. >> >> Given this function:

Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Steven D'Aprano
From: Steven D'Aprano I'd like to run a quick survey. There is no right or wrong answer, since this is about your EXPECTATIONS, not what Python actually does. Given this function: def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Tim Chase
On 2018-06-23 23:08, Jim Lee wrote: >>> On 06/23/2018 10:03 PM, Steven D'Aprano wrote: def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result what would you expect the result of calling test() to be?

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-25 Thread Tim Chase
On 2018-06-24 05:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, > since this is about your EXPECTATIONS, not what Python actually > does. > > Given this function: > > def test(): > a = 1 > b = 2 > result = [value for key, value in

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-24 Thread Ben Finney
Paul Moore writes: > On 24 June 2018 at 06:03, Steven D'Aprano > wrote: > > Given this function: > > > > def test(): > > a = 1 > > b = 2 > > result = [value for key, value in locals().items()] > > return result > > > > what would you expect the result of calling test() to be?

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-24 Thread Paul Moore
On 24 June 2018 at 06:03, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key, value in

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-24 Thread Jim Lee
On 06/23/2018 11:16 PM, Chris Angelico wrote: On Sun, Jun 24, 2018 at 4:08 PM, Jim Lee wrote: There are three locals: a, b, and result. Since result cannot be assigned a value until the list comp has been evaluated, I would expect the comp to return a value of "None" for result. An

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-24 Thread Chris Angelico
On Sun, Jun 24, 2018 at 4:08 PM, Jim Lee wrote: > There are three locals: a, b, and result. Since result cannot be assigned > a value until the list comp has been evaluated, I would expect the comp to > return a value of "None" for result. An argument could also be made for [1, > 2, []], but

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-24 Thread Jim Lee
On 06/23/2018 11:02 PM, Chris Angelico wrote: On Sun, Jun 24, 2018 at 3:44 PM, Jim Lee wrote: On 06/23/2018 10:03 PM, Steven D'Aprano wrote: I'd like to run a quick survey. There is no right or wrong answer, since this is about your EXPECTATIONS, not what Python actually does. Given this

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-24 Thread Chris Angelico
On Sun, Jun 24, 2018 at 3:44 PM, Jim Lee wrote: > > > On 06/23/2018 10:03 PM, Steven D'Aprano wrote: >> >> I'd like to run a quick survey. There is no right or wrong answer, since >> this is about your EXPECTATIONS, not what Python actually does. >> >> Given this function: >> >> >> def test(): >>

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-23 Thread Jim Lee
On 06/23/2018 10:03 PM, Steven D'Aprano wrote: I'd like to run a quick survey. There is no right or wrong answer, since this is about your EXPECTATIONS, not what Python actually does. Given this function: def test(): a = 1 b = 2 result = [value for key, value in

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-23 Thread Steven D'Aprano
On Sun, 24 Jun 2018 15:18:49 +1000, Chris Angelico wrote: > Personally, I think it should give you [1, 2], the two values from the > function's locals. Thank you, that's the sort of answer I'm looking for. (I'm not saying I didn't read your long and involved analysis, only that I'm not looking

Re: Quick survey: locals in comprehensions (Python 3 only)

2018-06-23 Thread Chris Angelico
On Sun, Jun 24, 2018 at 3:03 PM, Steven D'Aprano wrote: > I'd like to run a quick survey. There is no right or wrong answer, since > this is about your EXPECTATIONS, not what Python actually does. > > Given this function: > > > def test(): > a = 1 > b = 2 > result = [value for key,

Quick survey: locals in comprehensions (Python 3 only)

2018-06-23 Thread Steven D'Aprano
I'd like to run a quick survey. There is no right or wrong answer, since this is about your EXPECTATIONS, not what Python actually does. Given this function: def test(): a = 1 b = 2 result = [value for key, value in locals().items()] return result what would you expect the