首页 > 编程语言 > 详细

python获取文件路径

时间:2019-12-16 12:20:23      阅读:61      评论:0      收藏:0      [点我收藏+]
摘自:https://blog.csdn.net/Poo_Chai/article/details/89764001

import os root_path = os.path.abspath(os.path.join(os.getcwd(), "..")) print("""*********************** Path test:start..... ********************""") print("***获得当前路径***") cwd = os.getcwd() print(‘current path:‘, cwd) print(‘File exist or not:‘, os.path.exists(‘C:\\Users\\leo\\Desktop\\neu.softwarecollege.mySocialCloudSimulator/‘ ‘//data/relationship-pairs.csv‘)) print(‘File exist or not:‘, os.path.exists(‘../data/relationship-pairs.csv‘)) print("""*********************** Path test:end..... ********************""") print(os.path.abspath(os.path.dirname(__file__))) print(‘***获取上级目录***‘) print(os.path.abspath(os.path.dirname(os.path.dirname(__file__)))) print(os.path.abspath(os.path.dirname(os.getcwd()))) path = os.path.abspath(os.path.join(os.getcwd(), "..")) print(‘path=‘, path) print(‘File exist or not:‘, os.path.exists(path+‘/data/relationship-pairs.csv‘)) print(‘***获取上上级目录***‘) print(os.path.abspath(os.path.join(os.getcwd(), "../.."))) ———————————————— 版权声明:本文为CSDN博主「Poo_Chai」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/Poo_Chai/article/details/89764001

  python获取文件路径的代码如上所示。运行结果如下:

 

技术分享图片

 

python获取文件路径

原文:https://www.cnblogs.com/LiuYanYGZ/p/12048343.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!