[__div__ for .joinpath()] on 29.07.2005 04:48 Tony Meyer said the following: >>I, herewith, claim to have used it in the past. >>But I am indifferent as to if its needed, it just looks natural to me. > > So far there seem to have been a few +0s, but no +1s... > >>What I use quite often is:: >> >> path(__file__).dirname() / "somesiblingfileiknowisthere" >> >>you do not have to think about trailing slashes or absolute vs. >>relative. and its much better than:: >> >> from os.path import * >> join(dirname(__file__), "somesiblingfileiknowisthere") > > In what way is this "much better"?
because of the 'object-orientedness'. i hope we agree on that (that's the reason for a path PEP?). the first is only sugar for the explicit:: path(__file__).dirname().joinpath("blablablabalbal") and as i said +0 operator overloading is only good if it's intuitive for the majority. (or Guido i suppose, in case this majority-person does not show up) [snip] > Would you really choose this: > > p = Path() / "build" / "a" / "very" / "very" / "long" / "path" (Path() is the current dir I think) > > Over this: > > p = Path(os.path.join("build", "a", "very", "very", "long", "path")) > > ? A saving of six characters, and the second one is a lot clearer. If > there was a os.path.joinPath (or whatever name) function that returned a > Path object rather than a string, then you'd get: > > p = joinPath("build", "a", "very", "very", "long", "path") > > Which is better (clearer, more concise) than either of the others, IMO. actually for explicitness i would choose: (original jorendorff):: p = path("build").joinpath("any", "path", "you", "can", "imagine") or otherwise maybe:: p = path("alpha") / "and" / "omega" -- http://mail.python.org/mailman/listinfo/python-list