Skip to content

Instantly share code, notes, and snippets.

@heiths
Created November 29, 2013 01:37
Show Gist options
  • Save heiths/7700435 to your computer and use it in GitHub Desktop.
Save heiths/7700435 to your computer and use it in GitHub Desktop.
A simple way to search for and get info about a script.
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