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

Tarek Ziadé tarek at ziade.org
Tue Sep 23 15:34:41 CEST 2014


Le 23/09/14 15:03, Nick Coghlan a écrit :
> 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.
>
This is getting better and better :-)




More information about the Python-ideas mailing list