Python os.path.join使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huhuandk/article/details/86314848

函数作用:用于路径拼接。

  • 会从第一个以”/”开头的参数开始拼接,之前的参数全部丢弃。
  • 以上一种情况为先。在上一种情况确保情况下,若出现”./”开头的参数,会从”./”开头的参数的上一个参数开始拼接。

示例:

import os

print("1:",os.path.join('father','/son','a.txt'))
print("2:",os.path.join('/father','/son','/a.txt'))
print("3:",os.path.join('father','./son','a.txt'))

结果:
1: /son\a.txt
2: /a.txt
3: father\./son\a.txt

猜你喜欢

转载自blog.csdn.net/huhuandk/article/details/86314848
今日推荐