Skip to content

Instantly share code, notes, and snippets.

@patwooky
Created September 21, 2016 17:06
Show Gist options
  • Save patwooky/6e2a74641ae351929756b1cc6dec6cc2 to your computer and use it in GitHub Desktop.
Save patwooky/6e2a74641ae351929756b1cc6dec6cc2 to your computer and use it in GitHub Desktop.
importing modules and querying module paths
'''
a little test to query the full path of the currently running module
'''
import os
import sys
print 'module name is', __name__ # if the module is not imported, __name__ will return '__main__'. else will return name of current module
print os.path.abspath(__file__) # returns the full path and filename of the current module
print sys.modules[__name__].__file__ # another way to find the current path and filename. returns the exact same thing as os.path.abspath(__file__)
print os.path.split(os.path.abspath(__file__)) # splits the full path into directory and file name. returns [path, filename.ext]
print os.path.splitdrive(os.path.split(os.path.abspath(__file__))[0]) # splits drive letter from rest of the path returns [drive, path]
print
print dir(os.path)
import currentModulePath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment