[Python-ideas] 'from os.path import FILE, DIR' or internal structure of filenames
MRAB
python at mrabarnett.plus.com
Sat Sep 28 18:51:29 CEST 2013
On 28/09/2013 12:34, Philipp A. wrote:
> as much as i would like the convenience, python has very few magic
> globals, and they all have names encased in 4 underscores.
>
> if we really add more globals, why not __abs_file__ and __abs_dir__ or
> sth. like that?
>
+1
1. Do we need them?
2. If we do, then I agree with __abs_file__ and __abs_dir__.
>
> 2013/9/28 anatoly techtonik <techtonik at gmail.com
> <mailto:techtonik at gmail.com>>
>
> 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 [ ].
>
> So it will be nice to see normalization of Python file name after
> the import to reduce mess and make its behaviour predictable -
> http://stackoverflow.com/questions/7116889/python-file-attribute-absolute-or-relative
>
>
> ----[ possible spec. draft for a beautiful internal structure ]--
> The Python interpreter should provide run-time information about:
> 1. order of import sequence
> 2. names of imported modules
> 3. unique location for each imported module which unambiguously
> identifies it
> 4. run-time import dependency tree (not sure about this, but it can
> help with debugging)
> 5. information about sys.path entry where this module was imported from
> 6. information about who and when added this sys.path entry
>
More information about the Python-ideas
mailing list