Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nick Coghlan
On 7 May 2018 at 14:33, Nathaniel Smith wrote: > On Sun, May 6, 2018 at 8:47 PM, Nick Coghlan wrote: > > On 7 May 2018 at 13:33, Nathaniel Smith wrote: > >> > >> Spit-balling: how about __filepath__ as a > >> lazily-created-on-first-access

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Mike Miller
On 2018-05-06 19:13, Nick Coghlan wrote: Specifically, the ones I'd have in mind would be: - dirname (aka os.path.dirname) - joinpath (aka os.path.join) - abspath (aka os.path.abspath) Yes, I end up importing those in most scripts currently. Just "join" has worked fine, although I could

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nathaniel Smith
On Sun, May 6, 2018 at 8:47 PM, Nick Coghlan wrote: > On 7 May 2018 at 13:33, Nathaniel Smith wrote: >> >> Spit-balling: how about __filepath__ as a >> lazily-created-on-first-access pathlib.Path(__file__)? >> >> Promoting os.path stuff to builtins just as

Re: [Python-ideas] Add "default" kw argument to operator.itemgetter and operator.attrgetter

2018-05-06 Thread Raymond Hettinger
> On May 6, 2018, at 6:00 AM, Steven D'Aprano wrote: > > On Thu, May 03, 2018 at 04:32:09PM +1000, Steven D'Aprano wrote: > >> Maybe I'm slow today, but I'm having trouble seeing how to write this as >> a lambda. > > Yes, I was definitely having a "cannot brain, I have

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nick Coghlan
On 7 May 2018 at 13:33, Nathaniel Smith wrote: > Spit-balling: how about __filepath__ as a > lazily-created-on-first-access pathlib.Path(__file__)? > > Promoting os.path stuff to builtins just as pathlib is emerging as > TOOWTDI makes me a bit uncomfortable. > pathlib *isn't*

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Tim Peters
[Tim] >> I have a long history of arguing that magically created lexically >> nested anonymous functions try too hard to behave exactly like >> explicitly typed lexically nested functions, but that's the trendy >> thing to do so I always lose ;-) [Nick Coghlan ] > You have the

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nathaniel Smith
Spit-balling: how about __filepath__ as a lazily-created-on-first-access pathlib.Path(__file__)? Promoting os.path stuff to builtins just as pathlib is emerging as TOOWTDI makes me a bit uncomfortable. On Sun, May 6, 2018 at 8:29 PM, Nick Coghlan wrote: > On 7 May 2018 at

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Nick Coghlan
On 7 May 2018 at 12:35, Chris Angelico wrote: > On Mon, May 7, 2018 at 12:13 PM, Nick Coghlan wrote: > > So I have a different suggestion: perhaps it might make sense to propose > > promoting a key handful of path manipulation operations to the status of >

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Tim Peters
[Tim] >> There's a difference, though: if `y` "leaks", BFD. Who cares? ;-) >> If `y` remains inaccessible, there's no way around that. [Chris] > That's Steve D'Aprano's view - why not just let them ALL leak? I don't > like it though. I didn't suggest that. I'm not suggesting changing _any_

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Nick Coghlan
On 7 May 2018 at 12:51, Nick Coghlan wrote: > If any other form of comprehension level name binding does eventually get > accepted, then inline scope declarations could similarly be used to hoist > values out into the surrounding scope: > > rem = None > while

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Chris Angelico
On Mon, May 7, 2018 at 12:34 PM, Tim Peters wrote: >> That's a fair point. But there is another equally valid use-case for >> assignment expressions inside list comps: >> >> values = [y + 2 for x in iter if (y := f(x)) > 0] >> >> In this case, it's just as obvious that the

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Nick Coghlan
On 7 May 2018 at 11:32, Tim Peters wrote: > I have a long history of arguing that magically created lexically > nested anonymous functions try too hard to behave exactly like > explicitly typed lexically nested functions, but that's the trendy > thing to do so I always lose

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Tim Peters
[Tim] >> In a different thread I noted that I sometimes want to write code like >> this: >> ... >>while any(n % (thisp := p) == 0 for p in small_primes): >>n //= thisp >> ... [Ryan Gonzalez ] > Couldn't you just do: > > def first(it): >return next(it, None) > >

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Matt Arcidy
On Sun, May 6, 2018 at 7:37 PM, Matt Arcidy wrote: >> Personally, I'd still like to go back to := creating a statement-local >> name, one that won't leak out of ANY statement. But the tide was >> against that one, so I gave up on it. > > yes. > > I have some probably tangential

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Matt Arcidy
> Personally, I'd still like to go back to := creating a statement-local > name, one that won't leak out of ANY statement. But the tide was > against that one, so I gave up on it. yes. I have some probably tangential to bad arguments but I'm going to make them anyways, because I think := makes

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Chris Angelico
On Mon, May 7, 2018 at 12:13 PM, Nick Coghlan wrote: > So I have a different suggestion: perhaps it might make sense to propose > promoting a key handful of path manipulation operations to the status of > being builtins? > > Specifically, the ones I'd have in mind would be: >

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Tim Peters
[Chris Angelico ] > ... > You're correct. The genexp is approximately equivalent to: > > def genexp(): > for p in small_primes: > thisp = p > yield n % thisp == 0 > while any(genexp()): > n //= thisp > > With generator expressions, since they won't

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Ryan Gonzalez
On May 6, 2018 8:41:26 PM Tim Peters wrote: In a different thread I noted that I sometimes want to write code like this: while any(n % p == 0 for p in small_primes): # divide p out - but what's p? But generator expressions hide the value of `p` that

Re: [Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Chris Angelico
On Mon, May 7, 2018 at 11:32 AM, Tim Peters wrote: > In a different thread I noted that I sometimes want to write code like this: > > while any(n % p == 0 for p in small_primes): > # divide p out - but what's p? > > But generator expressions hide the value of `p`

[Python-ideas] A comprehension scope issue in PEP 572

2018-05-06 Thread Tim Peters
In a different thread I noted that I sometimes want to write code like this: while any(n % p == 0 for p in small_primes): # divide p out - but what's p? But generator expressions hide the value of `p` that succeeded, so I can't. `any()` and `all()` can't address this themselves -

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Chris Angelico
On Mon, May 7, 2018 at 1:05 AM, George Fischhof wrote: >> On Sun, May 6, 2018, 1:54 AM Yuval Greenfield >> wrote: >>> >>> Hi Ideas, >>> >>> I often need to reference a script's current directory. I end up writing: >>> >>> import os >>> SRC_DIR =

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread George Fischhof
2018-05-06 15:28 GMT+02:00 Cody Piersall : > With PEP 562, the name __dir__ is off limits for this. > > Cody > > On Sun, May 6, 2018, 1:54 AM Yuval Greenfield > wrote: > >> Hi Ideas, >> >> I often need to reference a script's current directory. I

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Cody Piersall
With PEP 562, the name __dir__ is off limits for this. Cody On Sun, May 6, 2018, 1:54 AM Yuval Greenfield wrote: > Hi Ideas, > > I often need to reference a script's current directory. I end up writing: > > import os > SRC_DIR = os.path.dirname(__file__) > > > But I

Re: [Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Steven D'Aprano
On Sun, May 06, 2018 at 06:53:11AM +, Yuval Greenfield wrote: > Hi Ideas, > > I often need to reference a script's current directory. I end up writing: > > import os > SRC_DIR = os.path.dirname(__file__) > > > But I would prefer to have a new dunder for that. I propose: "__dir__". I > was

[Python-ideas] __dir__ in which folder is this py file

2018-05-06 Thread Yuval Greenfield
Hi Ideas, I often need to reference a script's current directory. I end up writing: import os SRC_DIR = os.path.dirname(__file__) But I would prefer to have a new dunder for that. I propose: "__dir__". I was wondering if others would find it convenient to include such a shortcut. Here are