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: 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: 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: Friday Finking: initialising values and implied tuples

2021-04-04 Thread 2QdxY4RzWzUUiLuE
On 2021-04-05 at 11:47:53 +1200, dn via Python-list wrote: > Did you spot how various contributors identified when they prefer one > method in a specific situation, but reach for another under differing > circumstances! What? Use cases matter? I'm *shocked*. :-/ Of all the methodologies I us

Re: Friday Finking: initialising values and implied tuples

2021-04-04 Thread Greg Ewing
On 5/04/21 11:47 am, dn wrote: I think I've read that the compiler is smart-enough to realise that the RHS 'literal-tuples'?'tuple-literals' are being used as a 'mechanism', and thus the inits are in-lined. It does indeed seem to do this in some cases: >>> def g(i, j, k): ... a, b, c = i, j,

Re: Friday Finking: initialising values and implied tuples

2021-04-04 Thread dn via Python-list
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; z2 = 9 >>> x3 =  8;  y3 =  8

Re: Friday Finking: initialising values and implied tuples

2021-04-04 Thread dn via Python-list
On 03/04/2021 11.25, Marco Ippolito wrote: >> (a) basic linear presentation: >> >> resource = "Oil" >> time = 1 >> crude = 2 >> residue = 3 >> my_list = "long" >> >> (b) using explicit tuples: >> >> ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" ) >> >> (c) linear and indent

Re: Friday Finking: initialising values and implied tuples

2021-04-03 Thread Rob Cliffe via Python-list
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; z2 = 9     x3 =  8;  y3 =  8;  z3 = 10 (please imagine it's in a fixed font with everything neatly vertica

Re: Friday Finking: initialising values and implied tuples

2021-04-02 Thread 2QdxY4RzWzUUiLuE
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; z2 = 9 >     x3 =  8;  y3 =  8;  z3 = 10 > (please imagine it's in a fixed font with everything neatly vertically > aligned). > This has see-at-a-glance STRUCTURE: the lette

Re: Friday Finking: initialising values and implied tuples

2021-04-02 Thread Alan Gauld via Python-list
On 02/04/2021 23:10, dn via Python-list wrote: > When there are several items to be defined and initialised, how do you > prefer to format the code, and why? > (a) basic linear presentation: > > resource = "Oil" > time = 1 > crude = 2 > residue = 3 > my_list = "long" In production code I'd almos

Re: Friday Finking: initialising values and implied tuples

2021-04-02 Thread Rob Cliffe via Python-list
On 02/04/2021 23:10, dn via Python-list wrote: (f) the space-saver: resource = "Oil"; time = 1; crude = 2; residue = 3; my_list = "long" IMO This can be OK when the number of items is VERY small (like 2) and not expected to increase (or decrease).  Especially if there are multiple simil

Re: Friday Finking: initialising values and implied tuples

2021-04-02 Thread 2QdxY4RzWzUUiLuE
On 2021-04-02 at 19:25:07 -0300, Marco Ippolito wrote: > > (a) basic linear presentation: > > > > resource = "Oil" > > time = 1 > > crude = 2 > > residue = 3 > > my_list = "long" > > > > (b) using explicit tuples: > > > > ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" )

Re: Friday Finking: initialising values and implied tuples

2021-04-02 Thread Marco Ippolito
> (a) basic linear presentation: > > resource = "Oil" > time = 1 > crude = 2 > residue = 3 > my_list = "long" > > (b) using explicit tuples: > > ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" ) > > (c) linear and indented tuples: > > ( > resource, > time, >

Friday Finking: initialising values and implied tuples

2021-04-02 Thread dn via Python-list
When there are several items to be defined and initialised, how do you prefer to format the code, and why? Apprentice: learn options Journeyman: consider and discuss Python Master: define, declare, and correct/advise/tutor Some do not realise that using a tuple is a convenient way to convey mul