argparse action on default values

Chris Angelico rosuav at gmail.com
Thu Jan 9 10:24:11 EST 2014


On Thu, Jan 9, 2014 at 5:20 AM, Florian Lindner <mailinglists at xgm.de> wrote:
> def norm_path(*parts):
>     """ Returns the normalized, absolute, expanded and joined path, assembled of all parts. """
>     parts = [ str(p) for p in parts ]
>     return os.path.abspath(os.path.expanduser(os.path.join(*parts)))

Apologies for responding to something that's not the point of your
post, but I see this as a job for map, rather than a list comp:

def norm_path(*parts):
    """ Returns the normalized, absolute, expanded and joined path,
assembled of all parts. """
    path = os.path.join(*map(str,parts))
    return os.path.abspath(os.path.expanduser(path))

(or completely onelinered, since you don't seem to mind longish lines).

ChrisA



More information about the Python-list mailing list