Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
berrondo opened this Issue · 2 comments

3 participants

@berrondo

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 path.py i need to do this:

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

or:

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

or:

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?

@oliverjanik

How about:

new_dir = path(os.path.join(var1, var2, var3))
@jaraco
Owner

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 closed this issue from a commit
@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
fc2862a
@jaraco jaraco closed this in fc2862a
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.