Mercurial > hg > config
changeset 20:03fc1f76db91
adding dotpath python helper
author | k0s <k0scist@gmail.com> |
---|---|
date | Mon, 22 Feb 2010 13:59:07 -0500 |
parents | 9e2d6f9974a2 |
children | 099a3bfa2852 |
files | python/dotpath.py |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/dotpath.py Mon Feb 22 13:59:07 2010 -0500 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +import sys + +def filename(dotpath): + path = dotpath.split('.') + while path: + try: + module = __import__('.'.join(path)) + return module.__file__.rstrip('c') + except ImportError: + path.pop() + +def main(args=sys.argv[1:]): + for arg in args: + try: + _filename = filename(arg) + except Exception, e: + print e + continue + print _filename + +if __name__ == '__main__': + main()