[Python-ideas] os.path.abspath - optional startdir argument

Ryan rymg19 at gmail.com
Fri Jul 25 03:54:00 CEST 2014


Instead, though, you'd do:

f = (Path(_file__) / 'app.conf').open()

https://docs.python.org/3/library/pathlib.html#pathlib.Path.open 


"Juancarlo Añez" <apalala at gmail.com> wrote:
>On a related topic...
>
>What's missing in Python 3.4, is that most modules with functions or
>methods that take file names or file paths as parameters are not
>pathlib-aware, so a mandatory str(mypahtlibpath) is required.
>
>For example, you cannot do:
>
>f = open(Path(_file__) / 'app.conf')
>
>It will fail.
>
>But pathlib as part of the standard lib is new, so it's OK.
>
>It will take time how know where in the module dependency hierarchy it
>should belong.
>
>Cheers,
>
>
>
>On Thu, Jul 24, 2014 at 5:19 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>
>> On 7/24/2014 11:30 AM, Wolfgang Maier wrote:
>>
>>> On 24.07.2014 17:21, Juancarlo Añez wrote:
>>>
>>
>>  Better yet, use the pathlib module.
>>>>
>>>
>> Thank for the reminder. I took a better look at it.
>>
>>
>>  As it stands, the pathlib module is only provisional plus,
>>>
>>
>> 'Provisional' means that there *could* be a few api changes that
>would
>> break code. The module is not going away.
>>
>>
>>  IMO, kind of overkill for a simple task like that.
>>>
>>
>> Overkill?
>>
>> import pathlib as path
>> import os.path as path
>>
>> are equally easy
>>
>> The 'simple task' combines joining, normalizing, and 'absoluting'.
>> pathlib.Path joins, Path.resolve normalizes and 'absolutes'. Together
>they
>> combine the functions of os.path.join, os.path.abspath and
>> os.path.normpath, with a nicer syntax, and with OS awareness.
>>
>> >>> path.Path('../../../Python27/lib', 'ast.py').resolve()
>> WindowsPath('C:/Programs/Python27/Lib/ast.py')
>>
>> If one starts with a Path object, as would be typical, one can use
>'/' to
>> join, as JuanCarlo mentioned.
>>
>> >>> base = path.Path('.')
>> >>> (base / '../../../Python27/lib' / 'ast.py').resolve()
>> WindowsPath('C:/Programs/Python27/Lib/ast.py')
>>
>> --
>> Terry Jan Reedy
>>
>>
>>
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>
>
>
>-- 
>Juancarlo *Añez*
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Python-ideas mailing list
>Python-ideas at python.org
>https://mail.python.org/mailman/listinfo/python-ideas
>Code of Conduct: http://python.org/psf/codeofconduct/

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140724/ec7c06f2/attachment.html>


More information about the Python-ideas mailing list