python的os.path.join()
1 >>> import os 2 >>> print("2:",os.path.join('/aaaa','/bbbb','/ccccc.txt')) 3 2: /ccccc.txt
5 >>> print("2:",os.path.join('/aaaa','/bbbb','ccccc.txt')) 6 2: /bbbb/ccccc.txt
7 >>> print("2:",os.path.join('/aaaa','bbbb','ccccc.txt')) 8 2: /aaaa/bbbb/ccccc.txt
9 >>> print("2:",os.path.join('/aaaa','/bbbb','ccccc.txt')) 10 2: /bbbb/ccccc.txt
11 >>> print("2:",os.path.join('/aaaa','/bbbb','/ccccc.txt')) 12 2: /ccccc.txt
13 >>> print("2:",os.path.join('aaaa','/bbbb','/ccccc.txt')) 14 2: /ccccc.txt
15 >>> print("2:",os.path.join('aaaa','/bbbb','ccccc.txt')) 16 2: /bbbb/ccccc.txt
17 >>> print("2:",os.path.join('aaaa','./bbbb','ccccc.txt')) 18 2: aaaa/./bbbb/ccccc.txt
结论:1.从最后添加的文件'ccccc.txt'开始看,出现第一个'/'时,添加path,'/'前面的所有都会被忽略。
2.要想第一个'/'前面的path也被添加,可以这样写'./'。