Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created February 21, 2012 01:32
Show Gist options
  • Save hidsh/1872822 to your computer and use it in GitHub Desktop.
Save hidsh/1872822 to your computer and use it in GitHub Desktop.
python path name test
import sys # args
import os.path
path_py_script = sys.argv[0]
print ' sys.argv[0] : "%s"' % path_py_script
print ' os.path.dirname() : "%s"' % os.path.dirname(path_py_script)
print ' os.path.basename() : "%s"' % os.path.basename(path_py_script)
print ' os.path.splitext() : "%s" "%s"' % os.path.splitext(path_py_script)
print ' example 1 : "%s"' % (os.path.splitext(path_py_script)[0] + '.cache')
# result
# D:\py>path_name_test.py
# sys.argv[0] : "D:\py\path_name_test.py"
# os.path.dirname() : "D:\py"
# os.path.basename() : "path_name_test.py"
# os.path.splitext() : "D:\py\path_name_test" ".py"
# example 1 : "D:\py\path_name_test.cache"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment