Created
November 29, 2013 01:37
-
-
Save heiths/7700435 to your computer and use it in GitHub Desktop.
A simple way to search for and get info about a script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def main(script_name=None): | |
g = globals() | |
#pass it a value or get a prompt. Example: file_name.py | |
script_name = raw_input("Name of the file:\n#") if script_name is None else script_name | |
base_name = script_name.split('.')[0] | |
#list of paths containing the script | |
paths = [i for i in sys.path if os.path.isdir(i) and script_name in os.listdir(i)] | |
print "\n------------Searching Python Path---------------" | |
if paths: | |
for path in paths: | |
print("Found {0}:\t{1}/{0}".format(script_name, path)) | |
else: | |
print("Could not find script in python's path") | |
print "\n--------------Checking for imports -------------" | |
if base_name in g.keys(): | |
print "{} loaded:\n".format(base_name, g[base_name]) | |
else: | |
print "{} not loaded".format(script_name) | |
print "--------------------------------------------------" | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment