[svn r56231] add a small script that tells where an import of a python module package would come from.
py.which is meant to be the equivalent of "which" in unix. --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									671f6a4660
								
							
						
					
					
						commit
						15b129a12e
					
				| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
#!/usr/bin/env python 
 | 
			
		||||
 | 
			
		||||
"""\
 | 
			
		||||
py.which [name]
 | 
			
		||||
 | 
			
		||||
print the location of the given python module or package name 
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    name = sys.argv[1]
 | 
			
		||||
    try:
 | 
			
		||||
        mod = __import__(name)
 | 
			
		||||
    except ImportError:
 | 
			
		||||
        print >>sys.stderr, "could not import:", name 
 | 
			
		||||
    else:
 | 
			
		||||
        try:
 | 
			
		||||
            location = mod.__file__ 
 | 
			
		||||
        except AttributeError:
 | 
			
		||||
            print >>sys.stderr, "module (has no __file__):", mod
 | 
			
		||||
        else:
 | 
			
		||||
            print location
 | 
			
		||||
		Loading…
	
		Reference in New Issue