Sorry for the top-post — iPhone email sucks.

But: in regard to the whole “what paths to use to find resource files” issue:

The “current working directory” concept can be very helpful. You put
your files in a directory tree somewhere— could be inside the package,
could be anywhere else.

Then all paths in your app are relative to the root of that location.
So all your app needs to do is set the cwd on startup, and you’re good
to go. So you may use __file__ once at startup (or not, depending on
configuration settings)

Alternatively, in the simple web server example, you have a root path
that gets tacked on automatically in you app, so again, you use
relative paths everywhere.

The concept of non-python-code resources being accessible within a
package is really a separate issue than generic data files, etc. that
you may want to access and serve different way.

In short, if you have a collection of files that you want to access
from Python, and also might want to serve up with another application—
you don’t want to use a python resources system.

Now I’m a bit confused about the topic of the thread, but I do like
the idea of putting Path in a more accessible place. ( though a bit
concerned about startup time if it were a built in)

-CHB


Sent from my iPhone

> On Jun 5, 2018, at 6:30 AM, Michel Desmoulin <desmoulinmic...@gmail.com> 
> wrote:
>
> There are very few programs that never use any path operation.
>
> Opening a file is such a common one we have a built-in for it with
> open(), but you usually need to do some manipulation to get the file
> path in the first place.
>
> We have __file__, but the most common usage is to get the parent dir,
> with os or pathlib.
>
> Websites open static files and configurations file.
>
> GUI open files to be processed.
>
> Data processing open data source files.
>
> Terminal apps often pass files as a parameters.
>
> All those paths you may resolve, turn absolute, check against and so on.
> So much that pathlib.Path is one of the things I always put in a
> PYTHONSTARTUP since you need it so often.
>
> I think Path fits the bill for being a built-in, I feel it's used more
> often than any/all or zip, and maybe enumerate.
>
> Besides, it would help to make people use it, as I regularly meet dev
> that keep import os.path because of habits, tutorials, books, docs, etc.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to