[Python-au] blind spot with os.path

Mike Dewhirst miked at dewhirst.com.au
Thu Oct 15 09:21:48 UTC 2009


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


--- 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/*.*'





More information about the python-au mailing list