Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 3
    Good ancillary material. :-) Devil's advocate, though: sometimes you want to differentiate file paths from directory paths by appending the path separator. Nice thing about os.path.join is that it will collapse them: assert os.path.join('/home/cdleary/', 'foo/', 'bar/') == '/home/cdleary/foo/bar/' Commented Mar 15, 2009 at 13:23
  • 1
    It doesn't make a (technical) difference though! os.path.isdir will tell you whether a certain path is a directory (folder) Commented Mar 15, 2009 at 13:28
  • 3
    Yep, it's just to indicate to someone reading the code whether you expect a path to be a directory or a file. Commented Mar 15, 2009 at 13:40
  • 1
    The convention on windows is that files have an extension, always. it's not likely at all (under normal circumstances) to have a text file with a path such as c:\path\data Commented Mar 15, 2009 at 13:54
  • 7
    ..or you can represent them as "c:/mypath" and forget your backslash woes altogether :-) Commented Mar 15, 2009 at 21:50