[Python-ideas] 'from os.path import FILE, DIR' or internal structure of filenames
Cameron Simpson
cs at zip.com.au
Sun Sep 29 01:26:41 CEST 2013
On 28Sep2013 08:19, anatoly techtonik <techtonik at gmail.com> wrote:
| FILE = os.path.abspath(__file__)
| DIR = os.path.abspath(os.path.dirname(__file__))
| ?
|
| Repeated pattern for referencing resources relative to your scripts. Ideas
| about alternative names / locations are welcome.
|
| In PHP these are __FILE__ and __DIR__. For Python 3 adding __dir__ is
| impossible, because the name clashes with __dir__ method (which is not
| implemented for module object, but should be [ ] for consistency). Also
| current __file__ is rarely absolute path, because it is never normalized [
| ].
Maybe I'm grumpy this morning (though I felt the same reading this yesterday).
-1 for any names commencing with __ (or even _).
-1 for new globals.
-1 because I can imagine wanting different nuances on the definitions
above; in particular for DIR I can well imagine wanting bare
dirname(abspath(FILE)) - semanticly different to your construction.
There's lots of scope for bikeshedding here.
-1 because this is trivial trival code.
-1 because you can do all this with relative paths anyway, no need for abspath
-1 because I can imagine being unable to compute abspath in certain
circumstances ( certainly on older UNIX systems you could be
inside a directory without sufficient privileges to walk back
up the tree for getcwd and its equivalents )
-0 for adding some kind of convenience functions to importlib(?) for this
(+0 except that I can see heaps of bikeshedding)
Cheers,
--
Cameron Simpson <cs at zip.com.au>
In an insane society, the sane man must appear insane.
- Keith A. Schauer <keith at balrog.dseg.ti.com>
More information about the Python-ideas
mailing list