[python]获取当前路径用来构造相对路径的几种方法

时间:2023-01-18 18:47:28
print('getcwd', os.getcwd())
print('sysargv', sys.argv)
print('realpath', os.path.realpath(sys.argv[0]))
print('realpath.split', os.path.split(os.path.realpath(sys.argv[0]))[0]) 
print('__file__', __file__)
print('__file__.dir', os.path.dirname(__file__))