[Tutor] os.path.join on windows 2000

Scott Widney SWidney@ci.las-vegas.nv.us
Tue, 5 Feb 2002 14:52:01 -0800


> -----Original Message-----
> From: Danny Ruttle [mailto:danny@intuitivemedia.com]

> 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'

In your code above the base directory is "C:/site_root" yet in the traceback
it's listed as "C:/test". Is it possible that W2K is substituting one value
for another?

Scott