[Tutor] os.path.join on windows 2000

Danny Ruttle danny@intuitivemedia.com
Tue, 05 Feb 2002 17:33:39 +0000

I have a class which parses the contents of one file and
writes to another file - here's a snippet of the constructor:

class line_parser:
def __init__(self, base_dir, in_file, out_file):

         self.handle = open(os.path.join(base_dir,in_file),"r")
         <snipped here>

Here's the calling line:

if __name__ == "__main__":
     my_instance = line_parser("c:/site_root","s.txt","test1.txt")

Here's the error raised in Windows 2000 Pro:

Traceback (most recent call last):
   File "C:\Python21\Pythonwin\pywin\framework\scriptutils.py", line 301, 
in RunScript
     exec codeObject in __main__.__dict__
   File "C:\Python21\database\pg_extract.py", line 58, in ?
     first = line_parser("c:/test","s.txt","test1.txt")
   File "C:\Python21\database\pg_extract.py", line 10, in __init__
     self.handle = open(os.path.join(base_dir,in_file),"r")
IOError: [Errno 2] No such file or directory: 'c:/test\\s.txt'

I'm using ActiveState with Python version 2.1.1.  If I run the code in 
windows 98
using the same version of ActiveState Python everything works fine.

Note that I'm using forward slashes since the application I'm developing
needs to work on Unix and Windows.

I've tried setting the os.sep variable to '/' but this did not work.
I've also tried using '\\' as a directory separator and this has no effect.

It seems this is a bug in the Win2k implementation.
Has anyone come across this problem?

BTW: I am using FAT32 File system.  I created the site_root directory
logged in as danny and also installed PythonWin (I am a member of