[Tutor] referring to subfolders
pine508 at hotmail.com
Sat Jan 17 06:20:34 CET 2009
I have been using absolute paths in my programs, but
want to get out of the habit as I try to run them on
other computers. I was surprised to find that this
type of reference didn't work:
path = '/subfolder/myfile.py'
But instead I did it this way and it works:
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?
It seems like something quick/built-in like the first way should
work, or maybe I am misunderstanding something?
Windows Live™: Keep your life in sync.
More information about the Tutor