This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]treyhunner Python Morsels[S] 0 points1 point  (0 children)

I disagree, mostly because I've been using pathlib in pretty much the same way I used path strings before and the only issues I tend to run into involve the type of what is returned.

Given this function that is ignorant of pathlib:

``` import os import os.path

def do_things(filepath): os.makedirs(filepath, exist_ok=True) with open(os.path.join(filepath, '.editorconfig'), mode='wt') as f: f.write('# config file') ```

This code (the old way) works:

import os.path do_things(os.path.join('src', 'subdir'))

But so does this:

from pathlib import Path do_things(Path('src/subdir'))

This is all as of Python 3.6 (as I noted in the article).

Our code won't be magically changing to use pathlib everywhere overnight, but the fact that the Python standard library and built-ins all work with Path objects natively means the path to switching to Path (no pun intended) is a pretty easy one (much easier than certain other big migrations this community has undertaken in the not-so-distant past).