Skip to content

How to make a path object from a list of strings? #12

berrondo opened this Issue Nov 16, 2012 · 2 comments

3 participants


I have this use case:

new_dir = os.path.join( var_a, var_b, var_c )

where each var evaluates to string and so, the first var is not a path object.

to use i need to do this:

new_dir = path('').joinpath( var_a, var_b, var_c )


new_dir = path.joinpath( path(var_a), var_b, var_c )


new_dir = path( var_a ).joinpath( var_b, var_c )

and i have lists too, which is a pain:

path('').joinpath(*List) ?
path.joinpath(path(p) for p in List) ?
path.joinpath(map(path, List)) ?
sum(map(path, List)) ?!
path(path.os.sep.join(List)) ?! :(

what do you think about pass lists to the constructor? or maybe joinpath to be a staticmethod?


How about:

new_dir = path(os.path.join(var1, var2, var3))
jaraco commented Dec 8, 2012

joinpath as a static method seems like a reasonable idea. It's certainly worth exploring.

I often use:

new_dir = path(var_a) / var_b / var_c

But I don't like it because the syntax is incongruent (var_a is treated differently than var_b, but they fundamentally represent the same concept.

@jaraco jaraco added a commit that closed this issue Jan 16, 2013
@jaraco Now joinpath may be invoked as a classmethod or as an instance method…
…. This allows construction of a path object from a list of strings. Fixes #12
@jaraco jaraco closed this in fc2862a Jan 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.