Created
September 21, 2016 17:06
-
-
Save patwooky/6e2a74641ae351929756b1cc6dec6cc2 to your computer and use it in GitHub Desktop.
importing modules and querying module paths
This file contains 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
''' | |
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 dir(os.path) |
This file contains 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 currentModulePath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment