Re: ValueError vs IndexError, unpacking arguments with string.split

2018-12-02 Thread Morten W. Petersen
On Sun, Dec 2, 2018 at 1:20 PM Chris Angelico wrote: > On Sun, Dec 2, 2018 at 11:08 PM Morten W. Petersen > wrote: > > > > On Sun, Dec 2, 2018 at 12:49 PM Chris Angelico wrote: > >> To my knowledge, len(x) == len(list(x)) for any core data type that > >> has a length. > > > > >>> len(range(0,10

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-12-02 Thread Chris Angelico
On Sun, Dec 2, 2018 at 11:08 PM Morten W. Petersen wrote: > > On Sun, Dec 2, 2018 at 12:49 PM Chris Angelico wrote: >> To my knowledge, len(x) == len(list(x)) for any core data type that >> has a length. > > >>> len(range(0,100,3)) > 34 > >>> range(0,100,3).__len__ > > >>> range(0,100,3).__len__

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-12-02 Thread Morten W. Petersen
On Sun, Dec 2, 2018 at 12:49 PM Chris Angelico wrote: > On Sun, Dec 2, 2018 at 10:36 PM Morten W. Petersen > wrote: > > While we're on the subject, I did a test in my Python interpreter: > > > > Python 3.6.7 (default, Oct 22 2018, 11:32:17) > > [GCC 8.2.0] on linux > > Type "help", "copyright",

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-12-02 Thread Chris Angelico
On Sun, Dec 2, 2018 at 10:36 PM Morten W. Petersen wrote: > While we're on the subject, I did a test in my Python interpreter: > > Python 3.6.7 (default, Oct 22 2018, 11:32:17) > [GCC 8.2.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> range(0,3,100) > ra

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-12-02 Thread Morten W. Petersen
On Sun, Dec 2, 2018 at 2:23 AM Chris Angelico wrote: > On Sun, Dec 2, 2018 at 11:55 AM Morten W. Petersen > wrote: > > > > On Sat, Dec 1, 2018 at 1:11 AM Chris Angelico wrote: > >> > >> On Sat, Dec 1, 2018 at 10:55 AM Morten W. Petersen > wrote: > >> > But this raises the question of how to wr

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-12-01 Thread Chris Angelico
On Sun, Dec 2, 2018 at 11:55 AM Morten W. Petersen wrote: > > On Sat, Dec 1, 2018 at 1:11 AM Chris Angelico wrote: >> >> On Sat, Dec 1, 2018 at 10:55 AM Morten W. Petersen wrote: >> > But this raises the question of how to write Python code, >> > short and sweet, that could handle infinite itera

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-12-01 Thread Morten W. Petersen
On Sat, Dec 1, 2018 at 1:11 AM Chris Angelico wrote: > On Sat, Dec 1, 2018 at 10:55 AM Morten W. Petersen > wrote: > > But this raises the question of how to write Python code, > > short and sweet, that could handle infinite iterators in > > such an unpack with multiple variables to assign to. >

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Chris Angelico
On Sat, Dec 1, 2018 at 10:55 AM Morten W. Petersen wrote: > But this raises the question of how to write Python code, > short and sweet, that could handle infinite iterators in > such an unpack with multiple variables to assign to. > > Which I guess is mostly theoretical, as there are other > ways

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Morten W. Petersen
On Sat, Dec 1, 2018 at 12:25 AM Chris Angelico wrote: > On Sat, Dec 1, 2018 at 10:18 AM Morten W. Petersen > wrote: > > > > On Fri, Nov 30, 2018 at 7:25 PM Dan Sommers < > > 2qdxy4rzwzuui...@potatochowder.com> wrote: > > > > > On 11/30/18 12:00 PM, Morten W. Petersen wrote: > > > > > > > I gues

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Chris Angelico
On Sat, Dec 1, 2018 at 10:18 AM Morten W. Petersen wrote: > > On Fri, Nov 30, 2018 at 7:25 PM Dan Sommers < > 2qdxy4rzwzuui...@potatochowder.com> wrote: > > > On 11/30/18 12:00 PM, Morten W. Petersen wrote: > > > > > I guess syntax could be added, so that > > > > > > a, b, @c = some sequence >

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Morten W. Petersen
On Fri, Nov 30, 2018 at 7:25 PM Dan Sommers < 2qdxy4rzwzuui...@potatochowder.com> wrote: > On 11/30/18 12:00 PM, Morten W. Petersen wrote: > > > I guess syntax could be added, so that > > > > a, b, @c = some sequence > > > > would initialize a and b, and leave anything remaining in c. We cou

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Dan Sommers
On 11/30/18 12:00 PM, Morten W. Petersen wrote: > I guess syntax could be added, so that > > a, b, @c = some sequence > > would initialize a and b, and leave anything remaining in c. We could > then call this @ syntax "teh snek". Close. ;-) Try this: a, b, *c = [4, 5, 6, 7] -- https://ma

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Morten W. Petersen
On Fri, Nov 30, 2018 at 6:21 PM Dan Sommers < 2qdxy4rzwzuui...@potatochowder.com> wrote: > On 11/30/18 10:57 AM, Morten W. Petersen wrote: > > On Fri, Nov 30, 2018 at 4:25 PM Dan Sommers > <2qdxy4rzwzuui...@potatochowder.com> wrote: > [...] > > But since you mention it, why is it necessary to en

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Dan Sommers
On 11/30/18 10:57 AM, Morten W. Petersen wrote: > On Fri, Nov 30, 2018 at 4:25 PM Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: >> Python validates that the right hand side contains exactly the right >> number of elements before beginning to unpack, presumably to ensure a >> successfu

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Morten W. Petersen
On Fri, Nov 30, 2018 at 4:25 PM Dan Sommers < 2qdxy4rzwzuui...@potatochowder.com> wrote: > On 11/30/18 7:35 AM, Morten W. Petersen wrote: > > > ... but isn't it logical that the > > string is parsed and split, and then later the unpacking operation fails > > with an IndexError? > > With slightly s

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Dan Sommers
On 11/30/18 7:35 AM, Morten W. Petersen wrote: ... but isn't it logical that the string is parsed and split, and then later the unpacking operation fails with an IndexError? With slightly simpler code and the full text of the exception, the details becomes more apparent: >>> x, y = [4] Traceb

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Morten W. Petersen
On Fri, Nov 30, 2018 at 4:02 PM Peter Otten <__pete...@web.de> wrote: > Morten W. Petersen wrote: > > > I've been reading up on a bit of C++, Assembler etc. lately, so maybe my > > mind expected an IndexError because of that, but isn't it logical that > the > > string is parsed and split, and the

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Peter Otten
Morten W. Petersen wrote: > Hi there. > > I was adding a port specification feature to my surveil project as shown > here: > > https://github.com/morphex/surveil/commit/703318f87c4c450a37944b565a10718ef27b57b4 > > A bit later I was surprised when the script raised an exception, and that > I ha

ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Morten W. Petersen
Hi there. I was adding a port specification feature to my surveil project as shown here: https://github.com/morphex/surveil/commit/703318f87c4c450a37944b565a10718ef27b57b4 A bit later I was surprised when the script raised an exception, and that I had to catch a ValueError instead of an IndexErr