[Python-ideas] proposal: os.path.joinuser()

Chris Angelico rosuav at gmail.com
Tue Sep 23 10:40:57 CEST 2014


On Tue, Sep 23, 2014 at 5:19 PM, Tarek Ziadé <tarek at ziade.org> wrote:
> I realize I am using a lot this pattern:
>
>    >>> os.path.join(os.path.expanduser('~'), 'something', 'here')
>    '/Users/tarek/something/here'
>
>
> It's quite complicated, and not really intuitive.

Not every one-liner needs to be in the stdlib.

def joinuser(*parts, user=''):
    return os.path.join(os.path.expanduser('~'+user), *parts)

Suggestion: Build up your own utilities module (I used to call it
"oddsends" - Odds & Ends - although back when I started, it was a
Q-Basic file from which I would copy and paste code, rather than a
Python module from which I'd import), and put this kind of convenience
function in it. Then it's as simple as:

from utils import joinuser

at the top of your script.

ChrisA


More information about the Python-ideas mailing list