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

Brett Cannon brett at python.org
Mon May 7 12:52:52 EDT 2018


On Mon, 7 May 2018 at 08:17 Serhiy Storchaka <storchaka at gmail.com> 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 a module is in.  FWIW, I'd
> > probably use it.
>
> The question is *why* you need the absolute path to the directory the
> module is in? Taking into account the availability of
> importlib.resources etc.
>

And just "why", and "how often"? I'm sure we have all done it before, but
it isn't something that comes up *constantly*. And duplicating part of the
details what __spec__.location contains just to save an import and a line
to strip off the file seems unnecessary. Plus, this doesn't take into
consideration the fact that not every module is going to exist in a
directory (e.g. what if I loaded from a sqlite database?).

IOW I'm -1 on this addition to modules as I don't think it's difficult
enough or used enough to warrant adding the overhead of providing it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180507/a0e2e225/attachment.html>


More information about the Python-ideas mailing list