_fileNameToModuleName drek removal
Phlip
phlip_cpp at yahoo.com
Fri May 31 17:48:53 EDT 2002
Hypo Nt:
Ogle this:
def _fileNameToModuleName(fileName):
'TODO is there a way in Python to avoid this drek??'
assert fileName[-3:] == '.py'
if fileName[0] != '.': os.path.join('.', fileName)
fileName = fileName[:-3]
moduleName = string.split(fileName, os.sep)[1:]
moduleName = string.join(moduleName, '.')
assert moduleName[0] != '.'
return moduleName
That, platform neutral, converts a file name ./yak/yak/yak.py
into a module name yak.yak.yak
Is there some cleaner way to do this? Preferably built-in?
--
Phlip
http://www.c2.com/cgi/wiki?PyUnitTestBrowser
-- To catch a bug, you'v got to learn to think like a bug --
More information about the Python-list
mailing list