[Python-ideas] os.path.argparse - optional startdir argument
Wolfgang Maier
wolfgang.maier at biologie.uni-freiburg.de
Thu Jul 24 15:45:53 CEST 2014
Dear all,
currently, os.path.abspath(somepath) is, essentially, equivalent to
os.path.normpath(os.path.join(os.getcwd(),path)).
However, I'd find it useful, occasionally, to be able to specify a
starting directory other than the current working directory.
One such situation is when reading a config file of an application: if
you encounter a relative link in such a file, you'll typically want to
transform it into an absolute path using that application's working
directory as opposed to your own one.
My suggestion would be to add an optional startdir argument to abspath,
which, when provided would be used instead of os.getcwd(). If startdir
itself is not an absolute path either, it would be turned into one
through recursion.
Currently, you have to write:
os.path.normpath(os.path.join(startdir, path))
or even
os.path.normpath(os.path.join(os.path.abspath(startdir), path))
instead of the proposed:
os.path.abspath(path, startdir)
Before posting I checked the bug tracker and found that this idea has
been brought up years ago (http://bugs.python.org/issue9882), but not
pursued further.
The patch suggested there is a bit of an oversimplification, but I have
my own one, which I could provide if someone's interested.
For issue9882 it was suggested to bring it up on python-ideas, but to
the best of my knowledge that was never done, so I'm doing it now.
Thoughts ?
Wolfgang
More information about the Python-ideas
mailing list