scnzzh: ~/aaa >cat zzh1.py import os.path print(os.path.dirname(__file__)) abs_file_dir = os.path.abspath(os.path.dirname(__file__)) print(abs_file_dir) a = abs_file_dir + '../../' print(a) print(os.path.abspath(a)) scnzzh: ~/aaa >cat zzh2.py import os.path print(os.path.dirname(__file__)) abs_file_dir = os.path.abspath(os.path.dirname(__file__)) print(abs_file_dir) a = abs_file_dir + '/../../' print(a) print(os.path.abspath(a)) scnzzh: ~/aaa >python zzh1.py /home/scnzzh/aaa /home/scnzzh/aaa../../ /home/scnzzh scnzzh: ~/aaa >python /home/scnzzh/aaa/zzh1.py /home/scnzzh/aaa /home/scnzzh/aaa /home/scnzzh/aaa../../ /home/scnzzh scnzzh: ~/aaa >python /home/scnzzh/aaa/zzh2.py /home/scnzzh/aaa /home/scnzzh/aaa /home/scnzzh/aaa/../../ /home
标签:aaa,..,Python,concatenated,scnzzh,file,path,home From: https://www.cnblogs.com/zhangzhihui/p/17254186.html