def filenameToModuleName(fn):
"""Convert a name in the filesystem to the name of the Python module it is.
This is agressive about getting a module name back from a file; it will
always return a string. Agressive means 'sometimes wrong'; it won't look
at the Python path or try to do any error checking: don't use this method
unless you already know that the filename you're talking about is a Python
module.
"""
fullName = os.path.abspath(fn)
modName = os.path.splitext(os.path.basename(fn))[0]
while 1:
fullName = os.path.dirname(fullName)
if os.path.exists(os.path.join(fullName, "__init__.py")):
modName = "%s.%s" % (os.path.basename(fullName), modName)
else:
break
return modName
#boo python
评论列表
文章目录