[Python-au] blind spot with os.path

raf raf at raf.org
Thu Oct 15 09:06:47 UTC 2009


Mike Dewhirst wrote:

> The problem I find is that Python seems to be using the wrong default 
> path separator here ...
> 
> 'C:\\users\\miked\\py\\chemdata\\src\\getmsds\\testlinks\\leave_empty/*.*'
> 
> ... and which line can be seen below in context as part of the traceback.
> 
> I'm sure Windows did not add the /*.* and I certainly didn't. That 
> leaves Python as the obvious suspect.
> 
> Any clues appreciated
> 
> Thanks
> Mike

hi,

forward slash works fine on windows.
i don't think that's the problem.
does the leave_empty directory actually exist?
that might be the problem. i can't see mkdir
anywhere in the code.

cheers,
raf

> --- code being tested on Windows XP with Python 2.6 ---
> 
> class GetBase(object):
> 
>     def __init__(self, basedir=basedir, ext=ext):
>         self.basedir = basedir
>         self.ext = ext
> 
>     def filelist(self):
>         # return list of (ccode, filename) tuples
>         filelist = os.listdir(self.basedir)
>         retlist = []
>         for item in filelist:
>             if self.ext in item:
>                 (ccode, toss) = item.split("_", 1)
>                 retlist.append((ccode, item))
>         return retlist
> 
> 
> --- tests.py excerpt ---
> 
> import os, unittest
> import sds
> 
> emptydir = 'leave_empty'
> testdir = os.getcwd() + os.path.sep + 'testlinks'
> 
> class test_sds(unittest.TestCase):
> 
>     def test_files_not_exist(self):
>         """ 1 """
>         filesdir = testdir + os.path.sep + emptydir
>         print(filesdir)
>         tsto = sds.GetBase(filesdir)
>         numf = len(tsto.filelist())
>         print('%s' % numf)
>         self.assertEqual(numf == 0, True)
> 
> --- error ---
> 
> Traceback (most recent call last):
>   File "tests.py", line 85, in test_files_not_exist
>     numf = len(tsto.filelist())
>   File "C:\users\miked\py\chemdata\src\getmsds\sds.py", line 39, in 
> filelist
>     filelist = os.listdir(self.basedir)
> WindowsError: [Error 3] The system cannot find the path specified: 
> 'C:\\users\\miked\\py\\chemdata\\src\\getmsds\\testlinks\\leave_empty/*.*'
> 
> 
> 
> _______________________________________________
> python-au maillist  -  python-au at starship.python.net
> http://starship.python.net/mailman/listinfo/python-au



More information about the python-au mailing list