defprint_path(): print(f'os.getcwd() is {os.getcwd()}') print(f'sys.path[0] is {sys.path[0]}') print(f'sys.argv[0] is {sys.argv[0]}') print(f'__file__ is {__file__}') print(f'os.path.dirname(__file__) is {os.path.dirname(__file__)}') print(f'os.path.abspath(__file__) is {os.path.abspath(__file__)}') print(f'os.path.realpath(__file__) is {os.path.realpath(__file__)}') print(f'os.path.split(os.path.realpath(__file__))[0] is {os.path.split(os.path.realpath(__file__))[0]}')
------ module_a/getpath.py ------ os.getcwd() is /Users/vk/tmp/path sys.path[0] is /Users/vk/tmp/path/module_a sys.argv[0] is module_a/getpath.py __file__ is module_a/getpath.py os.path.dirname(__file__) is module_a os.path.abspath(__file__) is /Users/vk/tmp/path/module_a/getpath.py os.path.realpath(__file__) is /Users/vk/tmp/path/module_a/getpath.py os.path.split(os.path.realpath(__file__))[0] is /Users/vk/tmp/path/module_a --------------------------------- ------ module_a/module_b/getpath.py ------ os.getcwd() is /Users/vk/tmp/path sys.path[0] is /Users/vk/tmp/path/module_a sys.argv[0] is module_a/getpath.py __file__ is /Users/vk/tmp/path/module_a/module_b/getpath.py os.path.dirname(__file__) is /Users/vk/tmp/path/module_a/module_b os.path.abspath(__file__) is /Users/vk/tmp/path/module_a/module_b/getpath.py os.path.realpath(__file__) is /Users/vk/tmp/path/module_a/module_b/getpath.py os.path.split(os.path.realpath(__file__))[0] is /Users/vk/tmp/path/module_a/module_b ------------------------------------------