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

Nick Coghlan ncoghlan at gmail.com
Tue Sep 23 15:03:36 CEST 2014


On 23 September 2014 22:52, Tarek Ziadé <tarek at ziade.org> wrote:
> Le 23/09/14 14:51, Todd a écrit :
>>
>> What about something like os.path.homedir or os.homedir?  You could
>> use, for example, homedir() to get the home directory of the current
>> user, and homedir('username') to get the home directory of a given
>> user (if that is possible).
> Sounds way better!

Given the naming of site.getuserbase(), site.getusersite(), and
os.expanduser(), a simple "os.userdir()" (to parallel "os.curdir()")
may be appropriate.

Then making a path that is relative to the user dir absolute would be:

    abspath = os.path.join(os.userdir(), relpath)

While the inverse operation would be:

    relpath = os.path.relpath(abspath, start=os.userdir())

os.path.expanduser() would then be primarily about dealing with
*longer* paths that have "~" embedded, rather than the degenerate case
of "os.expanduser('~')".

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list