[Tutor] referring to subfolders

Kent Johnson kent37 at tds.net
Sat Jan 17 14:03:46 CET 2009


On Sat, Jan 17, 2009 at 12:20 AM, Che M <pine508 at hotmail.com> wrote:

> import os.path
> self.currentdir = os.curdir
> self.mysubfolder = os.path.join(self.currentdir, "subfolder")
> path = self.mysubfolder + '/myfile.py'
>
> Is this really the only way to do it,and so I have to import
> os.path each time I have a case where I refer to a subdirectory?

The advantage of os.path.join() (if you use it for all joins) is that
it is portable, it will use the appropriate path separator for the
platform it is running on. These days that is not such a big deal,
perhaps, as Mac OSX, Windows and Linux all accept / as a path
separator.

Kent


More information about the Tutor mailing list