码迷,mamicode.com
首页 > 编程语言 > 详细

python获取文件路径

时间:2019-12-16 13:36:45      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:get   src   imu   simulator   print   路径   tail   inf   details   

摘自: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获取文件路径

标签:get   src   imu   simulator   print   路径   tail   inf   details   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!