Re: meaning of: line, =

2015-02-06 Thread Rustom Mody
On Friday, February 6, 2015 at 6:40:23 PM UTC+5:30, Devin Jeanpierre wrote: > Sorry for late reply, I somehow missed this email. > > On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody wrote: > > The reason I ask: I sorely miss haskell's pattern matching in python. > > > > It goes some way: > > > ((x

Re: meaning of: line, =

2015-02-06 Thread Rustom Mody
On Friday, February 6, 2015 at 6:40:23 PM UTC+5:30, Devin Jeanpierre wrote: > Sorry for late reply, I somehow missed this email. > > On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody wrote: > > The reason I ask: I sorely miss haskell's pattern matching in python. > > > > It goes some way: > > > ((x

Re: meaning of: line, =

2015-02-06 Thread Devin Jeanpierre
Sorry for late reply, I somehow missed this email. On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody wrote: > The reason I ask: I sorely miss haskell's pattern matching in python. > > It goes some way: > ((x,y),z) = ((1,2),3) x,y,z > (1, 2, 3) > > But not as far as I would like: > ((x,y)

Re: meaning of: line, =

2015-02-05 Thread Gregory Ewing
Chris Angelico wrote: [] = x # is equivalent to try: next(iter(x)) except StopIteration: pass else: raise ValueError("too many values to unpack (expected 0)") It's a way of asserting that an iterator is exhausted! But why disallow using () for the same thing? This is a blatant case of outright

Re: meaning of: line, =

2015-02-05 Thread Chris Angelico
On Fri, Feb 6, 2015 at 12:12 PM, Devin Jeanpierre wrote: > Here's another example, one that still exists in Python 3: > [] = '' () = '' > File "", line 1 > SyntaxError: can't assign to () > > The syntax explicitly blacklists (), but forgets to blacklist []. So... this is actually a re

Re: meaning of: line, =

2015-02-05 Thread Devin Jeanpierre
On Thu, Feb 5, 2015 at 8:08 AM, Ian Kelly wrote: > On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano > wrote: >> Devin Jeanpierre wrote: >>> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote: [result] = f() result > 42 Huh, was not aware of that alternate syntax.

Re: meaning of: line, =

2015-02-05 Thread Gregory Ewing
Devin Jeanpierre wrote: On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote: On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote: [result] = f() result Huh, was not aware of that alternate syntax. Nor are most people. Nor is Python, in some places -- it seems like peop

Re: meaning of: line, =

2015-02-05 Thread Tim Chase
On 2015-02-05 09:08, Ian Kelly wrote: > > Got an example where you can use a,b but not [a,b] or (a,b)? > > >>> def f(a, (b, c)): > ... print a, b, c > ... Interesting. I knew that at one point you could do this with lambdas but never thought to do it with regular functions. There are ti

Re: meaning of: line, =

2015-02-05 Thread Rustom Mody
On Thursday, February 5, 2015 at 10:15:29 PM UTC+5:30, Rustom Mody wrote: > On Thursday, February 5, 2015 at 9:39:27 PM UTC+5:30, Ian wrote: > > On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano wrote: > > > Devin Jeanpierre wrote: > > > > > >> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote: >

Re: meaning of: line, =

2015-02-05 Thread Tim Chase
On 2015-02-05 08:45, Rustom Mody wrote: > > >>> def f(a, (b, c)): > > ... print a, b, c > > What the hell is that?! > First I am hearing/seeing it. > Whats it called? "tuple parameter unpacking", removed in Py3 https://www.python.org/dev/peps/pep-3113/ -tkc -- https://mail.python.org/ma

Re: meaning of: line, =

2015-02-05 Thread Skip Montanaro
Tuple packing. No longer supported in Python 3, but in available in Python <= 2. Skip On Thu, Feb 5, 2015 at 10:45 AM, Rustom Mody wrote: > On Thursday, February 5, 2015 at 9:39:27 PM UTC+5:30, Ian wrote: >> On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano wrote: >> > Devin Jeanpierre wrote: >>

Re: meaning of: line, =

2015-02-05 Thread Rustom Mody
On Thursday, February 5, 2015 at 9:39:27 PM UTC+5:30, Ian wrote: > On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano wrote: > > Devin Jeanpierre wrote: > > > >> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote: > >>> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten wrote: > Another alternative i

Re: meaning of: line, =

2015-02-05 Thread Ian Kelly
On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano wrote: > Devin Jeanpierre wrote: > >> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote: >>> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote: Another alternative is to put a list literal on the lefthand side: >>

Re: meaning of: line, =

2015-02-05 Thread Steven D'Aprano
Devin Jeanpierre wrote: > On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote: >> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote: >>> Another alternative is to put a list literal on the lefthand side: >>> >> def f(): yield 42 >>> >>> ... >> [result] = f() >> res

Re: meaning of: line, =

2015-02-05 Thread Devin Jeanpierre
On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote: > On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote: >> Another alternative is to put a list literal on the lefthand side: >> > def f(): yield 42 >> >> ... > [result] = f() > result >> 42 > > Huh, was not aware of

Re: meaning of: line, =

2015-02-05 Thread ast
"ast" a écrit dans le message de news:54d227ef$0$3292$426a7...@news.free.fr... thanks for the answers -- https://mail.python.org/mailman/listinfo/python-list

Re: meaning of: line, =

2015-02-04 Thread Chris Angelico
On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote: > Another alternative is to put a list literal on the lefthand side: > def f(): yield 42 > > ... [result] = f() result > 42 Huh, was not aware of that alternate syntax. > (If you're worried: neither the list nor

Re: meaning of: line, =

2015-02-04 Thread Peter Otten
Rustom Mody wrote: > Well its cryptic and confusing (to me at least) > And is helped by adding 2 characters: > > (result,) = f() > > instead of > > result, = f() Another alternative is to put a list literal on the lefthand side: >>> def f(): yield 42 ... >>> [result] = f() >>> result 42 (I

Re: meaning of: line, =

2015-02-04 Thread Ethan Furman
On 02/04/2015 07:04 AM, Chris Angelico wrote: > On Thu, Feb 5, 2015 at 1:38 AM, Albert-Jan Roskam wrote: >> I have also never seen this before, but perhaps this: >> > f = lambda: [42] > result, = f() > result >> 42 >> >> ... is slightly cleaner than this: > result = f()[0] > re

Re: meaning of: line, =

2015-02-04 Thread Rustom Mody
On Wednesday, February 4, 2015 at 8:14:29 PM UTC+5:30, Albert-Jan Roskam wrote: > - Original Message - > > > From: Chris Angelico > > Sent: Wednesday, February 4, 2015 3:24 PM > > Subject: Re: meaning of: line, = > > > > On Thu, Feb 5, 2015 at 1:08 AM

Re: meaning of: line, =

2015-02-04 Thread Chris Angelico
On Thu, Feb 5, 2015 at 1:38 AM, Albert-Jan Roskam wrote: > I have also never seen this before, but perhaps this: > f = lambda: [42] result, = f() result > 42 > > ... is slightly cleaner than this: result = f()[0] result > 42 They're not technically identical. If the thing

Re: meaning of: line, =

2015-02-04 Thread Albert-Jan Roskam
- Original Message - > From: Chris Angelico > To: > Cc: "python-list@python.org" > Sent: Wednesday, February 4, 2015 3:24 PM > Subject: Re: meaning of: line, = > > On Thu, Feb 5, 2015 at 1:08 AM, ast wrote: >> I dont understand why there is a c

Re: meaning of: line, =

2015-02-04 Thread Chris Angelico
On Thu, Feb 5, 2015 at 1:08 AM, ast wrote: > I dont understand why there is a comma just after line in the following > command: > > line, = plt.plot(x, np.sin(x), '--', linewidth=2) > > > I never saw that before > > Found here: > http://matplotlib.org/examples/lines_bars_and_markers/line_demo_dash

Re: meaning of: line, =

2015-02-04 Thread leo kirotawa
You'll find some explanation here: http://stackoverflow.com/questions/1708292/meaning-of-using-commas-and-underscores-with-python-assignment-operator On Wed, Feb 4, 2015 at 12:08 PM, ast wrote: > hello > > I dont understand why there is a comma just after line in the following > command: > > line

meaning of: line, =

2015-02-04 Thread ast
hello I dont understand why there is a comma just after line in the following command: line, = plt.plot(x, np.sin(x), '--', linewidth=2) I never saw that before Found here: http://matplotlib.org/examples/lines_bars_and_markers/line_demo_dash_control.html thanks -- https://mail.python.org/m