我自己写了几行代码测试了一下:
1 import os
2
3 filepath= os.path.abspath(__file__)
4 currentDir = os.path.dirname(os.path.abspath(__file__))
5 rootDir = os.path.abspath(os.path.join(currentDir, os.path.pardir))
6 print filepath
7 print currentDir
8
9 print os.path.abspath(os.path.join(currentDir, os.path.pardir))
10 print os.path.join(currentDir, os.path.pardir)
11 print rootDir
12 print os.path.pardir
结果如下,对照看一下,就明白
/home/zhoujie/count/test2.py
/home/zhoujie/count
/home/zhoujie
/home/zhoujie/count/..
/home/zhoujie
..