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

2018-05-17 Thread Chris Barker via Python-ideas
On Mon, May 7, 2018 at 9:17 AM, Steven D'Aprano wrote: > I'm arguing that for some people, your preferred syntax *is* more > distracting and hard to comprehend than the more self-descriptive > version with named functions. then use Path.joinpath() if you want. > From that

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

2018-05-16 Thread Eric Fahlgren
On Tue, May 15, 2018 at 10:11 PM Rob Speer wrote: > From what I can tell, if you wanted to exclude '__init__.py' from Nginx in > particular, you would have to write an unconventional Nginx configuration, > where you determine whether a path refers to a static file according

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

2018-05-15 Thread Rob Speer
> Are you saying that servers like Nginx or whatever your mini-server uses don’t have a way to blanket ignore files? That would surprise me, and it seems like a lurking security vulnerability regardless of importlib.resources or __init__.py files. I would think that you’d want to whitelist file

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

2018-05-15 Thread Barry Warsaw
On May 15, 2018, at 14:03, Rob Speer wrote: > Consider a mini-Web-server written in Python (there are, of course, lots of > these) that needs to serve static files. Users of the Web server will expect > to be able to place these static files somewhere relative to the

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

2018-05-15 Thread Rob Speer
While importlib.resources looks very good, I'm certain that it can't replace every use of __file__ for accessing files relative to your Python code. Consider a mini-Web-server written in Python (there are, of course, lots of these) that needs to serve static files. Users of the Web server will

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

2018-05-07 Thread Barry Warsaw
Yuval Greenfield wrote: I often need to reference a script's current directory. I end up writing: import os SRC_DIR = os.path.dirname(__file__) The question I have is, why do you want to reference the script's current directory? If the answer is to access other files in that directory,

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

2018-05-07 Thread Brendan Barnwell
On 2018-05-07 09:17, Steven D'Aprano wrote: I'm arguing that for some people, your preferred syntax*is* more distracting and hard to comprehend than the more self-descriptive version with named functions. And its not just a matter of*learning* the API, it is a matter of using it so often that

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

2018-05-07 Thread Eric Fahlgren
On Sun, May 6, 2018 at 9:30 PM, Mike Miller wrote: > 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

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

2018-05-07 Thread Brett Cannon
On Mon, 7 May 2018 at 08:17 Serhiy Storchaka wrote: > 07.05.18 17:42, Eric Snow пише: > > I'm not necessarily saying we should add ModuleSpec.dirname(), but it > > (or something like it) is what I'd advocate for *if* we were to add a > > convenient shortcut to the directory

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

2018-05-07 Thread Steven D'Aprano
On Mon, May 07, 2018 at 11:42:00AM +, Nathaniel Smith wrote: > On Mon, May 7, 2018, 03:45 Steven D'Aprano wrote: [...] > > So yes, its very distracting. > > Well, yes, you do have to know the API to use it, and if you happen to have > learned the os.path API but not the

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

2018-05-07 Thread Serhiy Storchaka
07.05.18 17:42, Eric Snow пише: I'm not necessarily saying we should add ModuleSpec.dirname(), but it (or something like it) is what I'd advocate for *if* we were to add a convenient shortcut to the directory a module is in. FWIW, I'd probably use it. The question is *why* you need the

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

2018-05-07 Thread Eric Snow
On Mon, May 7, 2018 at 7:14 AM, Serhiy Storchaka wrote: > * Additional burden on maintainers of import machinery. It is already too > complex, and __file__ is set in multiple places. Don't forgot about > third-party implementations. > > See also issue33277: "Deprecate

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

2018-05-07 Thread Serhiy Storchaka
06.05.18 09:53, Yuval Greenfield пише: 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

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

2018-05-07 Thread Chris Angelico
On Mon, May 7, 2018 at 8:44 PM, Steven D'Aprano wrote: > On Sun, May 06, 2018 at 09:33:03PM -0700, Nathaniel Smith wrote: > >> How is >> >> data_path = __filepath__.parent / "foo.txt" >> >> more distracting than >> >> data_path = joinpath(dirname(__file__), "foo.txt") > > >

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

2018-05-07 Thread Nick Coghlan
On 7 May 2018 at 21:42, Nathaniel Smith wrote: > On Mon, May 7, 2018, 03:45 Steven D'Aprano wrote: > >> On Sun, May 06, 2018 at 09:33:03PM -0700, Nathaniel Smith wrote: >> >> > How is >> > >> > data_path = __filepath__.parent / "foo.txt" >> > >> > more

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

2018-05-07 Thread Nick Coghlan
On 7 May 2018 at 20:44, Steven D'Aprano wrote: > First I have to work out what __filepath__ is, then I have to remember > the differences between all the various flavours of pathlib.Path > and suffer a moment or two of existential dread as I try to work out > whether or not

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

2018-05-07 Thread Nathaniel Smith
On Mon, May 7, 2018, 03:45 Steven D'Aprano wrote: > On Sun, May 06, 2018 at 09:33:03PM -0700, Nathaniel Smith wrote: > > > How is > > > > data_path = __filepath__.parent / "foo.txt" > > > > more distracting than > > > > data_path = joinpath(dirname(__file__), "foo.txt") > >

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

2018-05-07 Thread Steven D'Aprano
On Sun, May 06, 2018 at 09:33:03PM -0700, Nathaniel Smith wrote: > How is > > data_path = __filepath__.parent / "foo.txt" > > more distracting than > > data_path = joinpath(dirname(__file__), "foo.txt") Why are you dividing by a string? That's weird. [looks up the pathlib docs] Oh, that's

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] __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] __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] __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] __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