Re: Idiosyncratic python

2015-09-24 Thread Steven D'Aprano
On Thursday 24 September 2015 16:16, Paul Rubin wrote: > Steven D'Aprano writes: >> for k, v in mydict.items(): >> del(k) > > That looks wrong: it's deleting k from what? The local namespace. py> k = 23 py> print k 23 py> del k py> print k Traceback

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 08:02 AM, Steven D'Aprano wrote: I was looking at an in-house code base today, and the author seems to have a rather idiosyncratic approach to Python. For example: for k, v in mydict.items(): del(k) ... instead of the more obvious for v in mydict.values(): ...

Re: Idiosyncratic python

2015-09-24 Thread Ben Finney
Steven D'Aprano writes: > On Thursday 24 September 2015 16:16, Paul Rubin wrote: > > > Steven D'Aprano writes: > >> for k, v in mydict.items(): > >> del(k) > > […] The obvious intent is to iterate over the *values*

Re: Idiosyncratic python

2015-09-24 Thread Terry Reedy
On 9/24/2015 2:35 AM, Steven D'Aprano wrote: On Thursday 24 September 2015 16:16, Paul Rubin wrote: Steven D'Aprano writes: for k, v in mydict.items(): del(k) That looks wrong: it's deleting k from what? The local namespace. py> k = 23 py>

Idiosyncratic python

2015-09-24 Thread Steven D'Aprano
I was looking at an in-house code base today, and the author seems to have a rather idiosyncratic approach to Python. For example: for k, v in mydict.items(): del(k) ... instead of the more obvious for v in mydict.values(): ... What are your favorite not-wrong-just-weird

Re: Idiosyncratic python

2015-09-24 Thread Paul Rubin
Steven D'Aprano writes: > for k, v in mydict.items(): > del(k) That looks wrong: it's deleting k from what? > instead of the more obvious > for v in mydict.values(): > ... Maybe you mean while mydict: k, v = mydict.popitem() ...

Re: Idiosyncratic python

2015-09-24 Thread paul.hermeneutic
> A lot of our in base weird python comes from heavily C-wired people: > > The classic > for i in range(len(alist)): > print alist[i] > > with its twin brother > > i=0 > while i < len(alist): > print alist[i] > i += 1 > > And the even more annoying > > result = Result() > getResult(result) >

Re: Idiosyncratic python

2015-09-24 Thread Mark Lawrence
On 24/09/2015 13:50, paul.hermeneu...@gmail.com wrote: > A lot of our in base weird python comes from heavily C-wired people: > > The classic > for i in range(len(alist)): > print alist[i] > > with its twin brother > > i=0 > while i < len(alist): > print alist[i] > i += 1 > >

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 02:50 PM, paul.hermeneu...@gmail.com wrote: > A lot of our in base weird python comes from heavily C-wired people: > > The classic > for i in range(len(alist)): > print alist[i] > > with its twin brother > > i=0 > while i < len(alist): > print alist[i] > i += 1 >

Re: Idiosyncratic python

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 8:07 AM, jmp wrote: > result = getResult() > > For the later, the original weird form come from a C habit to allocate > returned structures within the caller and provide a pointer to it so the > function can fill the data in, otherwise the structure

Re: Idiosyncratic python

2015-09-24 Thread Laurent Pointal
wxjmfa...@gmail.com wrote: > Le jeudi 24 septembre 2015 08:02:38 UTC+2, Steven D'Aprano a écrit : >> >> >> What are your favorite not-wrong-just-weird Python moments? >> >> > Showing how to make Python 3.5.0 crash by > just using an "é", U+00E9. Like this ? Python 3.5.0 (default, Sep 24

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 04:26 PM, Ian Kelly wrote: On Thu, Sep 24, 2015 at 8:07 AM, jmp wrote: result = getResult() For the later, the original weird form come from a C habit to allocate returned structures within the caller and provide a pointer to it so the function can fill

Re: Idiosyncratic python

2015-09-24 Thread Mark Lawrence
On 24/09/2015 18:50, Laurent Pointal wrote: wxjmfa...@gmail.com wrote: Le jeudi 24 septembre 2015 08:02:38 UTC+2, Steven D'Aprano a écrit : What are your favorite not-wrong-just-weird Python moments? Showing how to make Python 3.5.0 crash by just using an "é", U+00E9. Would you like to

Re: Idiosyncratic python

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 12:04 PM, jmp wrote: > I'm not an expert but I think this "return by value thing" is only for C++. > In vintage C, you can only return something that fits within a register. If that was true at one time, it was before ANSI C. $ cat test.c #include

Re: Idiosyncratic python

2015-09-24 Thread Ned Batchelder
On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: > What are your favorite not-wrong-just-weird Python moments? I've seen this a number of times: dict_of_values.update({'key': some_value}) why not: dict_of_values['key'] = some_value I've considered writing a

Re: Idiosyncratic python

2015-09-24 Thread Laura Creighton
In a message of Thu, 24 Sep 2015 13:46:27 -0700, Ned Batchelder writes: >On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: >> What are your favorite not-wrong-just-weird Python moments? > >I've seen this a number of times: > >dict_of_values.update({'key': some_value})

Re: Idiosyncratic python

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 7:08 AM, Laura Creighton wrote: > In a message of Thu, 24 Sep 2015 13:46:27 -0700, Ned Batchelder writes: >>On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: >>> What are your favorite not-wrong-just-weird Python moments? >>

Re: Idiosyncratic python

2015-09-24 Thread Mark Lawrence
On 24/09/2015 07:02, Steven D'Aprano wrote: I was looking at an in-house code base today, and the author seems to have a rather idiosyncratic approach to Python. For example: for k, v in mydict.items(): del(k) ... instead of the more obvious for v in mydict.values(): ... What

Re: Idiosyncratic python

2015-09-24 Thread sohcahtoa82
On Wednesday, September 23, 2015 at 11:02:38 PM UTC-7, Steven D'Aprano wrote: > I was looking at an in-house code base today, and the author seems to have a > rather idiosyncratic approach to Python. For example: > > > for k, v in mydict.items(): > del(k) > ... > > > instead of the

Re: Idiosyncratic python

2015-09-24 Thread Todd
Using list indexing with booleans in place of a ternary operator. a = False b = [var2, var1][a] Instead of: b = var1 if a else var2 On Sep 24, 2015 8:06 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > I was looking at an in-house code base today, and the author seems to

Re: Idiosyncratic python

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 2:54 AM, Todd wrote: > Using list indexing with booleans in place of a ternary operator. > > a = False > b = [var2, var1][a] > > Instead of: > > b = var1 if a else var2 Be careful - these are not semantically identical. The first one evaluates both

Re: Idiosyncratic python

2015-09-24 Thread Akira Li
Mark Lawrence writes: > On 24/09/2015 07:02, Steven D'Aprano wrote: >> I was looking at an in-house code base today, and the author seems to have a >> rather idiosyncratic approach to Python. For example: >> >> for k, v in mydict.items(): >> del(k) >> ... >> >>

Re: Idiosyncratic python

2015-09-24 Thread Steven D'Aprano
On Thu, 24 Sep 2015 04:54 pm, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thursday 24 September 2015 16:16, Paul Rubin wrote: >> >> > Steven D'Aprano writes: >> >> for k, v in mydict.items(): >> >> del(k)

Re: Idiosyncratic python

2015-09-24 Thread Todd
On Sep 24, 2015 18:59, "Chris Angelico" wrote: > > On Fri, Sep 25, 2015 at 2:54 AM, Todd wrote: > > Using list indexing with booleans in place of a ternary operator. > > > > a = False > > b = [var2, var1][a] > > > > Instead of: > > > > b = var1 if a else

Re: Idiosyncratic python

2015-09-24 Thread Steven D'Aprano
On Fri, 25 Sep 2015 02:54 am, Todd wrote: > Using list indexing with booleans in place of a ternary operator. > > a = False > b = [var2, var1][a] > > Instead of: > > b = var1 if a else var2 Ah, you youngsters... :-) Using a bool to index into a list used to be the standard idiom, before the

Re: Idiosyncratic python

2015-09-24 Thread Steven D'Aprano
On Fri, 25 Sep 2015 06:46 am, Ned Batchelder wrote: > On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano > wrote: >> What are your favorite not-wrong-just-weird Python moments? > > I've seen this a number of times: > > dict_of_values.update({'key': some_value}) > > why