I am trying to create a function that will take in a list of paths (from the parameter list), execute several functions from os.path on it (expandvars, expanduser, normpath), and finally join all those path values. So far it looks like this:
def normjoin(*p):
""" Uses os.path functions to normalize and join paths
*path - all the paths you want to join
return: normalized and joined string
"""
b_results = []
for b in p:
b_results.append(os.path.normpath(os.path.expandvars(os.path.expanduser(b))))
return os.path.join(b_results)
And this is how it looks in practice:
sharedir = normjoin("~", "Dropbox/SpideroakShared")
I plan to use this on both a win and linux system.
The return value will come looking like this ' "C:\\Users\\tgoldie", "Dropbox\\SpideroakShared"' which is not good.
Any ideas?
The body of the function should be indented.
You have
b_results = "", but then try toappend. That won’t work. You needb_results = [].Finally, you need to pass the items of
b_resultsas arguments toos.path.joinlike this: