[Python-ideas] Path conversion for f-strings

2019-05-12 Thread Batuhan Taskaya
Like repr and string the file system path is used alot and something like path!p might be handy. >>> class MyClass: ... def __fspath__(self): ... return "/home/batuhan" ... >>> assert f"{mc!p}" == f"{os.fspath(mc)}" Also it saves us to unnecessarily import os for only fspath().

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread James Lu
I think a Python version of longjmp() and setjmp() might be easier to understand. On Sun, May 12, 2019 at 6:23 PM David Mertz wrote: > On Sun, May 12, 2019, 5:36 PM Paul Moore wrote: > >> On Sun, 12 May 2019 at 21:06, David Mertz wrote: >> > I thought of 'as' initially, and it reads well as

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread David Mertz
On Sun, May 12, 2019, 5:36 PM Paul Moore wrote: > On Sun, 12 May 2019 at 21:06, David Mertz wrote: > > I thought of 'as' initially, and it reads well as English. But it felt > to me like the meaning was too different from the other meanings of 'as' in > Python. I might be persuaded otherwise. >

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread David Mertz
On Sun, May 12, 2019, 3:33 PM Gustavo Carneiro wrote: > # Hypothetical future labelled break: >> def find_needle_in_haystacks(): >> for haystack in glob.glob('path/to/stuff/*') label HAYSTACKS: >> fh = open(fname) >> header = fh.readline() >> if get_format(header) ==

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread David Mertz
I thought of "we could return immediately" shortly after I posted it. Yes, that's true in the example I wrote. But it's easy enough to vary it so that something happens after the loop as well. I also noticed that for the simple version, it might be slightly shorter to put the conditional inside

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread Gustavo Carneiro
On Sun, 12 May 2019 at 18:26, David Mertz wrote: > To be clear in this thread, I don't think I'm really ADVOCATING for a > multi-level break. My comments are simply noting that I personally fairly > often encounter the situation where they would be useful. At the same > time, I worry about

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread David Mertz
To be clear in this thread, I don't think I'm really ADVOCATING for a multi-level break. My comments are simply noting that I personally fairly often encounter the situation where they would be useful. At the same time, I worry about Python gaining sometimes-useful features that complicate the

Re: [Python-ideas] add an additional dataclasses.asdict option for non-dataclasses

2019-05-12 Thread Christopher Barker
On Sat, May 11, 2019 at 8:23 PM Eric V. Smith wrote: > >> https://www.python.org/dev/peps/pep-0557/#why-not-just-use-namedtuple >> > > you would know, but that reference talks about why they are not the same > as NamedTuple. > > > That section mentions why they’re not iterable. Search on

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread MRAB
On 2019-05-12 10:44, Steven D'Aprano wrote: On Sun, May 12, 2019 at 11:16:21AM +0200, Oleg Broytman wrote: On Sun, May 12, 2019 at 01:36:28AM -0700, Elias Tarhini wrote: > If I may propose `break n` as a replacement for the original message's > `break break ... break`, where n>0 is the number

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread haael
The concrete example I was working on when I started to miss double break. This is an implementation of polynomial long division in Galois field. Almost unmodified. With outer break, I would't need to use the `running` variable. In fact, for mathematical clarity, I would like to put a

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread Steven D'Aprano
On Sun, May 12, 2019 at 11:16:21AM +0200, Oleg Broytman wrote: > On Sun, May 12, 2019 at 01:36:28AM -0700, Elias Tarhini > wrote: > > If I may propose `break n` as a replacement for the original message's > > `break break ... break`, where n>0 is the number of contiguous loops to > > break out

Re: [Python-ideas] Break multiple loop levels

2019-05-12 Thread Oleg Broytman
On Sun, May 12, 2019 at 01:36:28AM -0700, Elias Tarhini wrote: > If I may propose `break n` as a replacement for the original message's > `break break ... break`, where n>0 is the number of contiguous loops to > break out of and `break 1` is synonymous with `break`. Seems easier on my >