Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

OS path

  • path
  • abspath
  • exists
  • basename
  • dirname
import sys
import os

path_to_thing = __file__
if len(sys.argv) == 2:
    path_to_thing = sys.argv[1]

print(path_to_thing)
print( os.path.basename(path_to_thing) )
print( os.path.dirname(path_to_thing) )
print( os.path.abspath(path_to_thing) )

print( os.path.exists(path_to_thing) )
print( os.path.isdir(path_to_thing) )
print( os.path.isfile(path_to_thing) )